我有一个视图屏幕,其上有两种不同的形式,将以不同的方式激活。如果单击第一个按钮,则会出现第一个表单,用户可以填写并提交,然后单击另一个按钮激活另一个表单,然后将其提交到另一个表格。我试着给它不同的每个提交按钮不同的名称,但我的控制器没有识别名称。任何帮助将不胜感激。 这是我目前的看法
<div class="container">
<form class="form-horizontal" role="form" method="post" id="head">
<div class="form-group">
<label for="warehouse" class="col-sm-2 control-label">Transaction type</label>
<div class="col-sm-7">
@Html.TextBoxFor(m => m.vwint0, ViewBag.action_flag == "Create" ? (object)new { @class = "form-control", style = "width : 120px", @maxlength = 10 } : new { @disabled = "disabled", style = "width : 120px" })
@Html.ValidationMessageFor(m => m.vwint0)
</div>
</div>
<div class="form-group">
<label for="code" class="col-sm-2 control-label">Customer code</label>
<div class="col-sm-7">
@Html.DropDownListFor(m => m.vwstring1, ViewBag.cus as SelectList, "Select", new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3">
<button type="submit" class="btn btn-primary" name="update" value="headsub">Submit</button>
</div>
</div>
</form>
<form class="form-horizontal" role="form" method="post" id="details">
<div class="form-group">
<label for="firstName" class="col-sm-2 control-label">Sale sequence number </label>
<div class="col-sm-9">
@Html.TextBoxFor(m => m.vwint0, new { @class = "form-control", style = "width : 80px", maxlength = 10 })
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Quote sequence</label>
<div class="col-sm-9">
@Html.TextBoxFor(m => m.vwstring9, new { @class = "form-control", style = "width : 80px", maxlength = 10 })
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Item code</label>
<div class="col-sm-9">
@Html.DropDownListFor(m => m.vwstring10, ViewBag.item as SelectList, "Select", new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3">
<button type="submit" class="btn btn-primary" name="update" value="detailsub">Submit</button>
</div>
</div>
</form>
</div>
在我的控制器中,我尝试了这个,但我的控制器甚至没有识别按钮名称。
if (update == "headsub")
{
AR_002_SALES gdoc = new AR_002_SALES();
gdoc.sale_sequence_number = glay.vwint0;
gdoc.customer_code = glay.vwstring1;
gdoc.currency_code = glay.vwstring2;
}
else
{
AR_002_QUOTE = new AR_002_QUOTE();
AR_002_QUOTE.sale_sequence_number = glay.vwint0;
AR_002_QUOTE.quote_sequence = glay.vwstring9;
AR_002_QUOTE.item_code = string.IsNullOrWhiteSpace(glay.vwstring10) ? "" : glay.vwstring10;
AR_002_QUOTE.quote_qty = glay.vwdclarray0[0];
AR_002_QUOTE.price = glay.vwdclarray0[1];
}
答案 0 :(得分:0)
而不是使用<form class="form-horizontal" role="form" method="post" id="head">
使用@using (Html.BeginForm("ActionMethod", "Controller", FormMethod.Post, new { @class = "form-horizontal" ,@id="head" }))
提交表单和操作方法将处理该表单并执行操作。同样,您也可以为另一个表单执行操作。
在.cshtml中,它看起来不会触及该控制器的任何操作方法。