我在页面上有两个按钮,我希望用户单击一个,然后他们都转到不同的页面,问题是我的httpPost属性没有触发。
这是我的控制器:
public ActionResult Index()
{
if (Session["AccountConfirmationViewModel"] != null)
{
AccountConfirmationViewModel accountConfirmationViewModel = Session["AccountConfirmationViewModel"] as AccountConfirmationViewModel;
if (accountConfirmationViewModel == null || !TryValidateModel(accountConfirmationViewModel))
{
return RedirectToAction("AccountSearch", "Home");
}
MobileStep1ViewModel mobileModel = new MobileStep1ViewModel();
mobileModel.GetMobileNumbers(accountConfirmationViewModel.CustomerReferenceNumber);
Session["MobileModel"] = mobileModel;
}
return View();
}
[HttpPost]
public ActionResult Index(string button)
{
if (button == "btnNotMobileQuery")
{
RedirectToAction("AcconutSearch", "Home");
}
else if (button == "btnMobileQuery")
{
RedirectToAction("SecurityQuestion", "Mobile");
}
return View();
}
以下是我的观点:
@model OutsourcedTicketPlatform.UI.ViewModels.Mobile.MobileStep1ViewModel
@using OutsourcedTicketPlatform.UI.ViewModels.Mobile
@{
MobileStep1ViewModel mobileModel = Session["MobileModel"] as MobileStep1ViewModel;
ViewBag.Title = "Mobile Issue";
}
<h2>Mobile Issue Reporter</h2>
<p>Hi @mobileModel.CustomerName are you phoning today to log the mobile device as lost or stolen?</p>
@Html.RadioButton("IsMobileQuery", "MobileQuery")Yes
@Html.RadioButton("IsMobileQuery", "NotMobileQuery")No
<br /><br />
<div id="NotMobileQuery" class="HideDiv">
<input type="submit" class="btn" id="btnNotMobileQuery" value="Proceed" />
</div>
<div id="ConfirmMobile" class="HideDiv">
<p>"Please Confirm your mobile number"</p>
@foreach (var items in mobileModel.MobileNumbers)
{
@Html.RadioButton("SelectedMobileNumber", items)@items
}
<br /><br />
<input type="submit" class="btn" id="btnMobileQuery" value="Next" />
</div>
<script src="../../Scripts/Controllers/Mobile/MobileStepOne.js" type="text/javascript"></script>
<script src="../../Scripts/ViewModels/Mobile/MobileStepOneViewModel.js" type="text/javascript"></script>
有谁能看出我做错了什么?我的第二个索引方法中是否需要参数?
答案 0 :(得分:0)
试试这个:
@model OutsourcedTicketPlatform.UI.ViewModels.Mobile.MobileStep1ViewModel
@using OutsourcedTicketPlatform.UI.ViewModels.Mobile
@{
MobileStep1ViewModel mobileModel = Session["MobileModel"] as MobileStep1ViewModel;
ViewBag.Title = "Mobile Issue";
}
@using(Html.BeginForm("Index","Your_controller_name",FormMethod.Post)){
<h2>Mobile Issue Reporter</h2>
<p>Hi @mobileModel.CustomerName are you phoning today to log the mobile device as lost or stolen?</p>
@Html.RadioButton("IsMobileQuery", "MobileQuery")Yes
@Html.RadioButton("IsMobileQuery", "NotMobileQuery")No
<br /><br />
<div id="NotMobileQuery" class="HideDiv">
<input type="submit" class="btn" id="btnNotMobileQuery" value="Proceed" />
</div>
<div id="ConfirmMobile" class="HideDiv">
<p>"Please Confirm your mobile number"</p>
@foreach (var items in mobileModel.MobileNumbers)
{
@Html.RadioButton("SelectedMobileNumber", items)@items
}
<br /><br />
<input type="submit" class="btn" id="btnMobileQuery" value="Next" />
</div>
}
<script src="../../Scripts/Controllers/Mobile/MobileStepOne.js" type="text/javascript"></script>
<script src="../../Scripts/ViewModels/Mobile/MobileStepOneViewModel.js" type="text/javascript"></script>
您可以使用FormCollection而不是字符串来获取视图中的所有值。