我试图在 MVC4 RAZOR 应用程序中单击按钮后将所选单选按钮的值发回控制器。然而,我没有在控制器中取回真正的期望值,只有 0。
部分查看代码:
@model Blah.FeatureViewModel
<script type="text/javascript">
function OnContinueClick() {
$('#tabs').load('@Url.Action("Continue", "Home")', { SelectedFeature : Model.SelectedFeature });
}
</script>
@using (Html.BeginForm())
{
<div>
@foreach (var feature in Model.FeatureDictionary)
{
<p>
@Html.RadioButtonFor(x => x.SelectedFeature, feature) @feature.Value
</p>
}
<input type="button" name="continueButton" id="continueButton" value="Continue" onclick="OnContinueClick()" />
</div>
}
查看型号代码:
using System.Collections.Generic;
namespace Blah.Models
{
public class FeatureViewModel
{
public Dictionary<int, string> FeatureDictionary { get; set; }
public KeyValuePair<int, string> SelectedFeature { get; set; }
}
}
控制器代码:
[HttpPost]
public ActionResult Continue(FeatureViewModel featureViewModel)
{
//pass data to another controller
}
我想我可能需要 Jquery 来回发值?