@html.hiddenfor id name,我可以删除Html.HiddenFor(model => model.Id),应用程序仍然有效。它是为了什么?...

如果VS为[HttpGet] Create创建强类型视图,我会得到模型的标记,如下所示。

请注意,为简洁起见,简化了代码。重要的是VS不包括Html.HiddenFor(model=>model.Id)。

//Create.cshtml

@model MvcMovie.Models.Movie

@using (Html.BeginForm())

{

@Html.ValidationSummary(true)

Movie

@Html.LabelFor(model => model.Title)

@Html.EditorFor(model => model.Title)

@Html.ValidationMessageFor(model => model.Title)

@Html.LabelFor(model => model.ReleaseDate)

@Html.EditorFor(model => model.ReleaseDate)

@Html.ValidationMessageFor(model => model.ReleaseDate)

}

现在我为类型ѭ4create创建一个名为Movie.cshtml的模板化HTML助手编辑器,如下所示。

请注意,为简洁起见,简化了代码。重要的是VS DOES包括Html.HiddenFor(model=>model.Id)。

//Movie.cshtml

@model MvcMovie.Models.Movie

@Html.HiddenFor(model => model.Id)

@Html.LabelFor(model => model.Title)

@Html.EditorFor(model => model.Title)

@Html.ValidationMessageFor(model => model.Title)

@Html.LabelFor(model => model.ReleaseDate)

@Html.EditorFor(model => model.ReleaseDate)

@Html.ValidationMessageFor(model => model.ReleaseDate)

如果我使用这个模板,我必须改变Create.cshtml如下:

//Create.cshtml

@model MvcMovie.Models.Movie

@using (Html.BeginForm())

{

@Html.ValidationSummary(true)

Movie

@Html.EditorForModel()

}

问题是:

由于可以删除隐藏的字段形式而没有任何副作用,在这种情况下,隐藏字段是什么?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值