<%using (Html.BeginForm("ChangeLanguage", "AppController", FormMethod.Post))
{ %>
<div id="China">
<input id="imageChina" name="btnsubmitLan" type="image" value="CN" alt='China' src="/Content/Image/IconHH/FlatCN.gif" />
</div>
<div id="US">
<input id="ImageUS" name="btnsubmitLan" type="image" value="US" alt='English' src="/Content/Image/IconHH/FlatUS.jpg" />
</div>
<div id="VietNam">
<input id="ImageVN" name="btnsubmitLan" type="image" value="VN" alt='VietNam' src="/Content/Image/IconHH/FlatVN.jpg" />
</div>
<%} %>
在控制器中:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ChangeLanguage(string btnsubmitLan, FormCollection form)
{//chu yeu load o phan template
if (btnsubmitLan != null)
{
switch (btnsubmitLan)
{
case "VN": Session["language"] = "VN"; break;
case "CN":
case "US": Session["language"] = "EN"; break;
}
}
return RedirectToAction("Index");
}
但btnSubmit
总是null
。为什么????
答案 0 :(得分:0)
我将使用jQuery,然后对传入某种id的控制器执行AJAX帖子。
<input id="ImageVN" name="btnsubmitLan" type="image" value="VN" alt='VietNam' src="/Content/Image/IconHH/FlatVN.jpg" />
$('input').click( function() {
var id = this.attr("id");
//now do your ajax postback passing in the id.
} );