预填充HTML编辑器Asp.net MVC

编程入门 行业动态 更新时间:2024-10-09 06:27:52
本文介绍了预填充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

本文发布于:2023-05-31 14:01:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/393033.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编辑器   HTML   Asp   MVC   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!