小编kma*_*ton的帖子

在控制器中设置为True后,模型的Hidden bool字段仍为False

我在ViewModel类中有这个属性:

public bool AreSimilarEntitiesChecked { get; set; }

在我的控制器中,我将其值设置为"true"并返回带有模型的View:

model.AreSimilarEntitiesChecked = true;

return View(model).WithWarning("Check the similar mentors before saving!");
Run Code Online (Sandbox Code Playgroud)

在我的视图中有一个表单,我放置了这个属性的隐藏字段:

@Html.HiddenFor(m => m.AreSimilarEntitiesChecked)
Run Code Online (Sandbox Code Playgroud)

在View返回包含AreSimilarEntitiesChecked的模型后,其值保持为False desipte我在控制器中设置了True值.

我不知道它有什么问题.

生成的HTML:

<input name="AreSimilarEntitiesChecked" id="AreSimilarEntitiesChecked"
 type="hidden" value="False" data-val-required="The AreSimilarEntitiesChecked
 field is required." data-val="true">
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc hidden-field asp.net-mvc-4 html.hiddenfor

5
推荐指数
1
解决办法
2166
查看次数