我有一个视图,并将视图模型传递给它,以填充强类型输入。 视图模型创建得很好。 我调试了控制器以确保正确创建模型,并使用数据库(SQL Management Server 2008)中的正确值设置视图模型的属性,它正在执行此操作没有问题。 当我将视图模型传递到视图中时,只会填充一些强类型输入,而其他输入则不会。 我已经检查过以确保我的所有输入都指向正确的模型参数。 该表单由6个页面组成,我正在使用Kendo UI TabStrip来保持页面分离。 视图模型相当大,所以我想知道这是否是一个因素。 基本功能是用户可以开始填写表单,将其保存到数据库,检索他们填写的内容,然后在以后完成。 以下是一些示例代码:
以下是视图的代码段:
@model myWilmer.Models.QuoteViewModel <section id="quoteEntry"> @Html.ValidationSummary(true) @using (Html.BeginForm("CreateQuote", "Quotes", FormMethod.Post, new { id = "quotesForm" })) { @Html.TextBoxFor(m => m.QuoteNum, new { @class = "k-textbox", Value = "", id = "quoteNumber"}) }以下是视图模型的片段:
public class QuoteViewModel { public QuoteViewModel() { } [Display(Name = "Quote Number:")] [Required] [RegularExpression(@"^[0-9]+$")] public int QuoteNum { get; set; } }这是控制器的片段:
[HttpGet] public ActionResult Edit(int id) { QuoteViewModel qvm; //...Creating ViewModel return View(qvm); }I have a view and am passing a view model to it in order to populate the strongly typed inputs. The view model is created just fine. I have debugged the controller to ensure that model is created properly and the properties of the view model are set with the correct values from the database (SQL Management Server 2008), which it is doing with no problem. When I pass the view model into the view, only some of the strongly typed inputs are populated and the others aren't. I've checked to make sure that I have all of the inputs are pointing to the correct model parameter. The form consists of 6 pages that I'm using Kendo UI TabStrip to keep the pages separate. The view model is fairly large so I'm wondering if that is a factor. The basic functionality is that a user can start filling out a form, save it to the db, retrieve what they have filled out, and then complete it at a later date. Here is some sample code:
Here is a code snippet of the view:
@model myWilmer.Models.QuoteViewModel <section id="quoteEntry"> @Html.ValidationSummary(true) @using (Html.BeginForm("CreateQuote", "Quotes", FormMethod.Post, new { id = "quotesForm" })) { @Html.TextBoxFor(m => m.QuoteNum, new { @class = "k-textbox", Value = "", id = "quoteNumber"}) }Here is a snippet of the view model:
public class QuoteViewModel { public QuoteViewModel() { } [Display(Name = "Quote Number:")] [Required] [RegularExpression(@"^[0-9]+$")] public int QuoteNum { get; set; } }Here is a snippet of the controller:
[HttpGet] public ActionResult Edit(int id) { QuoteViewModel qvm; //...Creating ViewModel return View(qvm); }最满意答案
您通过使用Value =“”来覆盖Value。 删除它,它应该工作。
@Html.TextBoxFor(m => m.QuoteNum, new { @class = "k-textbox", id = "quoteNumber"})You are overriding the Value by having Value = "". Remove that and it should work.
@Html.TextBoxFor(m => m.QuoteNum, new { @class = "k-textbox", id = "quoteNumber"})更多推荐
发布评论