如何在ASP.Net Mvc中获取EditorFor的值并将按钮中的值作为参数传递

时间:2017-06-17 08:28:07

标签: asp.net-mvc razor

我想从我的编辑表单中传递一些Id的值。 假设我想要传递ProductId,CountryId和ModelId的值,我试过这样:

<input type="submit" value="Save" class="btn btn-default" onclick="return Update(@(model.ProductId),@(model.CountryId),@(model.ModelId) )/> 

但不行。 我在编辑表格中,这是我的表格。

@model Products.Models.Product

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>Product</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @Html.HiddenFor(model => model.ProductId)
        @Html.HiddenFor(model => model.CountryId)
    @Html.HiddenFor(model => model.ModelId)


        <div class="form-group">
            @Html.LabelFor(model => model.ProductName, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
            @Html.EditorFor(model => model.ProductName, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Model, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Model, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Model, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Model, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Status, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.Status, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.Status, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Save" class="btn btn-default" onclick="return Update(@(model.ProductId),@(model.CountryId),@(model.ModelId) )/> 
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div> 

谢谢!

1 个答案:

答案 0 :(得分:0)

fkey你将得到所有三个价值观。快乐的编码!