我有一个视图,我得到了我的Ajax.BeginForm,它提交它应该。但后来我有一个"保存图标"当我按下那个按钮时,我需要表格中的值。表单提交表示计算,并且保存图标可以保存全部。
但是当我按下保存图标(使用Url.Action(" SaveExcel","保存")时,我无法从文本框中获取值。我如何那样做?
我的HTML:
<a href="@Url.Action("SaveExcel", "Save")" title="Save"><img src="../../Images/glyphicons_446_floppy_save.png" alt="save" id="saveIcon"></a>
<!-- Contains forms and input for annuity calculation -->
<div class="calcInput" id="calcInput">
@using (Ajax.BeginForm("ShowDetailAnnuity", "Calculation", new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "CalcDetail",
LoadingElementId = "Loader",
}))
{
<div class="calculateBox">
<label for="calcOption">Choose value to calculate:</label>
<select id="calcOption" name="calcOption" title="Choose what value you want to calculate">
<option value="PMT" id="PMT" name="PMT">Payment (PMT)</option>
<option value="I" id="I" name="I">Interest (I)</option>
<option value="FV" id="FV" name="FV">Future value (FV)</option>
<option value="PV" id="PV" name="PV">Present value (PV)</option>
</select>
</div>
<div class="calculateBox" background-color="#777777">
@Html.Label("Present value (PV)", new { @id = "pvLabel" })
@Html.TextBox("PresentValue", null, new { @class = "PresentValue" })
@Html.Label("Future value (FV)", new { @id = "fvLabel" })
@Html.TextBox("FutureValue", null, new { @class = "FutureValue" })
@Html.Label("Interest rate", new { @id = "intRateLabel" })
@Html.TextBox("InterestRate", null, new { @class = "InterestRate" }) <br /> <br />
<input type="radio" name="advanceOrArrears" id="inAdvance" value="inAdvance" /> In advance<br />
<input type="radio" name="advanceOrArrears" id="inArrears" value="inArrears" /> In arrears
</div>
<div class="calculateBox">
<label for="startDate">Start date:</label>
<input type="date" id="StartDate" name="startdate" title="Choose start date for your calculation" /><br />
@Html.Label("Payment frequency")
<select id="PmtFreq" name="PmtFreq" title="Choose the payment frequency, for example: Every month">
<option value="Monthly">Monthly</option>
<option value="Quarterly">Quarterly</option>
</select><br /><br />
@Html.Label("No of payment periods")
@Html.TextBox("PaymentPeriods")
@Html.Label("Date time convention")
<select id="DTC" name="DTC" title="Choose your Date time convention">
<option value="360/360">360/360</option>
<option value="365/365">365/365</option>
</select><br /><br />
<input type="submit" id="CalcBtn" class="calcBtn" name="SubmitBtn" value="Calculate" title="Calculate your calculation" />
</div>
}
</div>
我的控制器:
public class SaveController : Controller
{
public ActionResult SaveExcel(string PresentValue) //Can't get PresentValue here..
{
return View();
}
}
我尝试在控制器中使用文本框的名称作为参数,我也尝试了Request.Form [&#34; PresentValue&#34;]但是没有任何工作
答案 0 :(得分:1)
听起来你需要两个提交按钮。
尝试将保存按钮转换为表单中的提交按钮,以便您拥有:
<input type="submit" name="SubmitButton" value="Calculate"/>
<input type="submit" name="SubmitButton" value="Save"/>
然后在你的控制器中,通过以下方式区分按下哪个按钮:
public ActionResult SaveExcel(string PresentValue, string SubmitButton)
{
if(SubmitButton == "Save") .... <save code>
if(SubmitButton == "Calculate") .... <calc code>
return View();
}