如何在剃刀中分配一个变量并传递另一个变量

时间:2012-11-09 12:03:40

标签: asp.net-mvc asp.net-mvc-3 razor model

我想从我的模型中获取一些信息,编辑一个变量并将其传递给post函数。这是我的模特:

public class TaskInputModel
{
    [Required]
    [Display(Name = "Input Value")]
    public decimal Value { get; set; }

    public long InputId { get; set; }

    public MetriceModelTaskShedule[] Tasks;
}

这是我的Index.cshtml:

@model MetriceWeb.Models.TaskInputModel

@foreach (var item in Model.Tasks)
    {

        using (Html.BeginForm())
        {
@Html.ValidationSummary(true)
<fieldset>
    <div class="editor-label">
        @Html.LabelFor(model => item.Task)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model =>  model.Value)
        @Html.ValidationMessageFor(model =>model.Value)
    </div>

    @Html.Hidden("Model.InputId", Model.InputId)

    <p>
        <input type="submit" value="Create" />
    </p>
</fieldset>
        }
}

我收到的就像那样:

[HttpPost]
    public ActionResult Index(TaskInputModel model)
    {
        ...
    }

当我提交时只有InputId有一些值,Value总是0.当我删除行:@ Html.Hidden(“Model.InputId”,Model.InputId)值是可以的,但我不知道如何接收InputId。你能告诉我怎么办?

1 个答案:

答案 0 :(得分:0)

问题解决了。我只需要使用@ Html.Hidden(“InputId”,Model.InputId)而不是@Html.Hidden(“Model.InputId”,Model.InputId)

相关问题