开发者

How can I tell which image has been clicked?

<%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&开发者_如何学Gogt;
    <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>
<%} %>

In controller :

    [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");
    }

But btnSubmit always null. Why????


I'd be using jQuery and then do an AJAX post to a controller passing in an id of some sort.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜