我可以在同一页面MVC上做一个AcceptVerbs(HttpVerbs.Get / Post)和hijaxing吗?

时间:2010-04-30 13:17:11

标签: c# javascript jquery html asp.net-mvc

我正在使用Hijaxing,我将有三个按钮,Prev,Add和Next。 hijaxing既可以使用Add,也可以使用Next按钮。

上一个按钮设置为'onclick =“history.back(-1)”' 添加按钮由'(Html.BeginForm(“添加”,“主页”))'表单触发,劫持Jquery,工作正常。
下一步按钮与“添加”按钮的作用相同。我想在Next按钮中点击Controller中的[AcceptVerbs(HttpVerbs.Post)]。有什么建议?

... 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" />
    <% } %>

1 个答案:

答案 0 :(得分:3)

看起来你正试图让2个提交按钮调用不同的动作。

请参阅here了解最佳方法。

相关问题