控制器中的操作:
public JsonResult AccountEdit(Guid? id) //id = 4a01aadd-c61a-4524-95f6-e88a665c0745
{
//ModelState.Clear(); <------- strange code
var model = DAL.AccountGet(id); <-- get model from database
return new JsonResult
{
Data = new
{
html = this.RenderPartialView("View", model),
},
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}
渲染的视图:
<div>@Model.Id</div> d2afb9a8-fb43-4237-9f34-abc7e5b59a41
<div>@Html.TextBoxFor(model => model.Id)</div> 4a01aadd-c61a-4524-95f6-e88a665c0745
<div>@Html.TextBoxFor(model => Model.Id)</div> 4a01aadd-c61a-4524-95f6-e88a665c0745
@Html.HiddenFor(model => model.Id) 4a01aadd-c61a-4524-95f6-e88a665c0745
只有第1行才是正确的ID
a)如果在所有行中取消注释ModelState.Clear()
将为“d2afb9a8-fb43-4237-9f34-abc7e5b59a41
” - 正确的值。
b)如果将AccountEdit(Guid?id)更改为AccountEdit(Guid? id2 )
c)模型的其他属性(参数中缺少)呈现正确
我的问题是为什么?