单击提交按钮后,如何将当前项目ID和文本框值发送到控制器。 :|
@model propertyMgmt.Models.Property
<div class="container" id="tourpackages-carousel">
<div class="panel panel-default" style="width:inherit">
<div class="panel-heading">
<h4 style="font-family:Tahoma, Geneva, sans-serif;margin-left:-5px;">
<strong>@Model.PropertyDescription</strong></h4>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-6">
<div>
<img src="~/Image/@Model.PropertyImage" alt="" style="width:100%;height:300px">
</div>
</div>
<div class="col-md-6" style="margin-left:-8px;margin-top:-20px;">
<div style="background-color:#d9dadd">
<h3 style="margin-left:16px;">
<u>Property Details</u></h3>
<dl class="dl-horizontal">
<dt>Total Investment:</dt>
<dd>@Model.InvestmentAmount</dd>
<dt>Remaining Investment:</dt>
<dd>@Model.RemainingInvestmentAmount</dd>
<dt>Property Discription:</dt>
<dd>@Model.PropertyDescription</dd>
<dt>Property Cost:</dt>
<dd>@Model.PropertyCost</dd>
<dt>Country:</dt>
<dd>@Model.Country</dd>
<dt>City:</dt>
<dd>@Model.City</dd>
</dl>
@using (Html.BeginForm("AddInvestment","Home",FormMethod.Post))
{
<input type="number" id="investmentAmount" name="investmentAmount" /><br />
<input type="submit" value="Submit" />
}
</ div >
</ div >
</ div >
</ div >
</ div >
</ div >
以下是具有所需参数的控制器。
[HttpPost]
[Route("AddInvestment/{id}/{amount}")]
public ActionResult AddInvestment(int propertyId, double investmentAmount)
{
Investment investment = new Investment();
investment.PropertyId = propertyId;
investment.InvestorId = Convert.ToInt32(Session["UserId"]);
investment.InvestmentAmount = investmentAmount;
_investmentQueryProcessor.AddInvestment(investment);
RemainingInvestment(propertyId, investmentAmount);
RemainingInvestorBalance(investment.InvestorId, investmentAmount);
return View();
}
我想了解如何使用帮助程序标记传递上述参数的项目ID和文本框值。我也不确定中间的@using html.beginform。 :|任何帮助将不胜感激。
答案 0 :(得分:0)
当您提交表单时(如您的代码所示),数据将作为键值对(名称:值)提交。这是使用输入控件的name
属性完成的。如果你需要跟踪id,那么你需要将id放在它自己的&#34;键值对&#34; (在这种情况下,一个单独的输入控件)。像这样:
@using (Html.BeginForm("AddInvestment","Home",FormMethod.Post))
{
<input type="number" id="investmentAmount" name="investmentAmount" /><br />
<input type="hidden" id="propertyId" name="propertyId" value="@Model.PropertyId" /><br />
<input type="submit" value="Submit" />
}