如何判断单击了哪个图像?

时间:2010-01-24 02:44:56

标签: asp.net-mvc

<%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。为什么????

1 个答案:

答案 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.
} );