帖子ID在表单中不起作用 [英] Post ID doesn't Work in Form
问题描述
我有一篇文章定义了一个新的数据库实体.用户输入所需的值并提交表单后,我将插入实体并将其发布回同一页面并显示其ID.当我按如下所示输入ID区域disabled
和readonly
时,它工作正常.
I have a post where I define a new database entity. After user enters needed values and submits the form, I insert the entity and post it back to the same page and display it's ID. When I enter the ID area disabled
and readonly
as below, it works perfectly.
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
ID:
@Html.TextBoxFor(model => model.ID, new { disabled = "disabled", @readonly = "readonly" })
<p><input type="submit" name="submit" value="Create" /></p>
</fieldset>
}
但是,当我仅按如下所示输入readonly
时,它确实插入了实体,但没有查看ID.
However, when I enter it only readonly
as in below, it does insert the entity, but doesn't view the ID.
@Html.TextBoxFor(model => model.ID, new { @readonly = "readonly" })
我在表单中还有另一个提交,该提交使用实体ID.但是,我不能在disabled
,因为它不会发布ID值.我该怎么办才能解决问题?
I have another submit in the form, which uses the entities ID. However, I cannot use disabled
here with the ID area, as it doesn't post the ID value. What can I do to resolve the issue?
推荐答案
我没有使用html扩展名,而是直接写道:
Instead of using html extensions, I directly wrote:
<input type="text" name="ID" value="@Model.ID" readonly />
它就像一种魅力.
这篇关于帖子ID在表单中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!