gpt4 book ai didi

asp.net-mvc - Html.HiddenFor 导致错误

转载 作者:行者123 更新时间:2023-12-01 01:43:09 30 4
gpt4 key购买 nike

当我尝试将 @Html.HiddenFor(@Model.ID) 添加到我的代码时,我在访问页面时收到以下错误:

Compiler Error Message: CS0411: The type arguments for method 'System.Web.Mvc.Html.InputExtensions.HiddenFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

我尝试阅读 MSDN,但是 the documentation is awful (他们没有在该方法的文档中提供单个代码示例。

这是我的看法:

@model CustomerService.Entity.Order
@using CustomerService.Entity
@{
ViewBag.Title = "OrderDetails";
}
<h2>
OrderDetails</h2>
@using (Html.BeginForm("HandleSubmit", "Home", FormMethod.Post))
{
<table border="1">
<tr>
<td>
<b>Order #</b>
</td>
<td>
@Model.ID
</td>
</tr>
<tr>
<td>
<b>Description</b>
</td>
<td>
@Model.Description
</td>
</tr>
<tr>
<td>
<b>Salesperson Name</b>
</td>
<td>
@Model.SalespersonName
</td>
</tr>
</table>
<h3>
Line Items</h3>

<input id="btnAddLineItem" type="submit" name="AddLineItem" value="AddLineItem" />

@Html.HiddenFor(@Model.ID)

<table border="1">
<tr>
<td>
<b>Line Item ID</b>
</td>
<td>
<b>Description</b>
</td>
</tr>
@for (int i = 0; i < @Model.LineItems.Count; ++i)
{
<tr>
<td>
@Model.LineItems[i].ID
</td>
<td>
@Model.LineItems[i].Description
</td>
</tr>
}</table>
}

最佳答案

HiddenFor 采用表达式。

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

关于asp.net-mvc - Html.HiddenFor 导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9658870/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com