开发者

Can I do a AcceptVerbs(HttpVerbs.Get/Post) and hijaxing on the same page MVC?

开发者 https://www.devze.com 2022-12-28 13:29 出处:网络
I am working with Hijaxing and I will have three buttons, Prev, Add, and Next.The hijaxing works with both the Add, and the Next button.

I am working with Hijaxing and I will have three buttons, Prev, Add, and Next. The hijaxing works with both the Add, and the Next button.

Prev button is set to 'onclick="history.back(-1)" '.

Add button is triggered by a '(Html.BeginForm("Add","Home"))' form with hijacking Jquery, which works fine.

Next button does does the same as the Add button. I would like the Next button to hit the [AcceptVerbs(HttpVerbs.Post)] in the Controller. Any suggestions?

CONTROLLER...

    [AcceptVerbs(HttpVerbs.Get)]
    public ActionResult Index()
    {
        return View();
    }

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult Index(string home)
    {
  开发者_开发问答      return RedirectToAction("Index", "Home");
    }

    public string GetQuote(Index index)
    {
        if (isNullorEmpty(index.name) != "")
            return "99";
        else
            return "Sorry";
    }

ASPX...

<script type="text/javascript">
    $(document).ready(function() {
        $("form[action$='GetQuote']").submit(function() {
            $.post($(this).attr("action"), $(this).serialize(), function(response) {
                $("#results").html(response);
            });
            return false;   
        });
    });    
</script>

    <%using (Html.BeginForm("GetQuote", "Stocks")) {%>
    <br />        
    <span id="results"></span>
    <br />
    <input id="txtSymbolName" name="name" type="text" />
    <br />        
    <input type="button" name="getPrev" value="Prev" onclick="history.back(-1)" />
    <input type="submit" value="Add" />          
    <input type="submit" name="home" value="Next" />
    <% } %>


It looks like you're trying to have 2 submit buttons call different actions.

See here for the best ways to do it.

0

精彩评论

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

关注公众号