C# 为什么在MVC5中的post操作方法中HiddenFor get null值?
我有一个局部视图,每当我发布表单时,hiddenfor都会得到null值。当我添加一个新的,它会得到空值,但当我编辑,它的作品很好。 我使用此代码检查错误C# 为什么在MVC5中的post操作方法中HiddenFor get null值?,c#,asp.net-mvc,razor,C#,Asp.net Mvc,Razor,我有一个局部视图,每当我发布表单时,hiddenfor都会得到null值。当我添加一个新的,它会得到空值,但当我编辑,它的作品很好。 我使用此代码检查错误 var errors = ModelState .Where(x => x.Value.Errors.Count > 0) .Select(x => new { x.Key, x.Value.Errors }) .ToArray(); 错误表示id字段是必需的。 我正在使用@Html.HiddenF
var errors = ModelState
.Where(x => x.Value.Errors.Count > 0)
.Select(x => new { x.Key, x.Value.Errors })
.ToArray();
错误表示id字段是必需的。
我正在使用@Html.HiddenFor(model=>model.Id)
表单是ajax.beginform
有什么问题
编辑:
这是有效的:
// Controller
[HttpPost]
public ActionResult Send(BitcoinTransactionViewModel **RedeemTransaction**)
{
}
// View
@using (Html.BeginForm("Send", "DepositDetails", FormMethod.Post, new { **RedeemTransaction** = Model }))
{
@Html.HiddenFor(m => m.Token);
@Html.HiddenFor(m => m.Transaction.TransactionId);
.
.
不清楚你在问什么。属性Id的类型是什么?您对其应用了哪些验证属性?您没有提供足够的代码来调试您的问题。请看一看以创建一个好问题。我没有应用任何验证属性,它的类型是INT。那么为什么它会为Null?当我添加新属性时,你是什么意思?你需要展示你的代码这和问题有什么关系
// Controller
[HttpPost]
public ActionResult Send(BitcoinTransactionViewModel **RedeemTransaction**)
{
}
// View
@using (Html.BeginForm("Send", "DepositDetails", FormMethod.Post, new { **RedeemTransaction** = Model }))
{
@Html.HiddenFor(m => m.Token);
@Html.HiddenFor(m => m.Transaction.TransactionId);
.
.