我想從我的Edit窗體傳遞一些Id的值。 讓說,我想通過產品編號,CountryId和ModelId的價值,我想是這樣的:我如何獲得ASP.Net Mvc中的EditorFor的值,並將參數中的值傳遞給參數
<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>
謝謝!
什麼是您的JavaScript'Update()'方法?爲什麼你將模型的原始值傳遞給它?你爲什麼不只是提交表格?您還需要顯示您的POST方法。 –
@StephenMuecke @StephenMuecke感謝您的回覆,因爲我將有三個按鈕,它們具有不同的功能,一個用於增加狀態,第二個用於減少狀態,另一個用於更新鑽孔表....這是可能的爲了得到我要求的那些價值? –
您的視圖中沒有顯示3個按鈕。而你的問題中沒有解釋這一點。你還沒有迴應我的任何疑問。沒有人可以回答這個問題。 –