本文介绍了预填充HTML编辑器Asp MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在页面加载时填充 @ Html.Editor 的值.这是我失败的尝试:
I want to fill with a value of the @Html.Editor when the page is loaded. Here is my failed attempt :
@Html.EditorFor(m => m, new { htmlAttributes = new { @class = "form-control" } })在剃刀"页面的顶部,我有这个:
At the top of the Razor page , I have this :
@model string这是我的控制器:
public ActionResult YeniBelge(string KimlikNo) { return View((object)KimlikNo); }说值不能为空.
我该如何纠正?谢谢.
推荐答案我怀疑您正在尝试为模型分配一个可能为null的字符串,该字符串永远不能为null.创建一个ViewModel类,并改用它:
I suspect you are trying to assign a string that could be null to your model, which can never be null. Create a ViewModel class and use it instead:
public class MyViewModel { public string TCKimlikNo { get; set; } } public ActionResult YeniBelge(string KimlikNo) { return View(new MyViewModel { KimlikNo = KimlikNo ?? "My Default Value" }); }然后在您看来:
@model MyViewModel @Html.EditorFor(m => m.TCKimlikNo, new { htmlAttributes = new { @class = "form-control" } })更多推荐
预填充HTML编辑器Asp.net MVC
发布评论