ASP.NET MVC:多使用提交按钮Ajax.BeginForm [英] ASP.NET MVC: Multiple submit buttons using Ajax.BeginForm

查看:235
本文介绍了ASP.NET MVC:多使用提交按钮Ajax.BeginForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建具有下一个按钮,previous按钮切换显示的图像的页面。

I want to create a page that has a next button and previous button that switches the image displayed.

有关为此我创建了一个 Ajax.BeginForm 并插入到它,图像和两个提交按钮。

For that purpose I created an Ajax.BeginForm and inserted into it, an image and two submit buttons.

我可以(我应该)已经提交多个按钮,里面的 Ajax.BeginForm

Can I (should I) have multiple submit buttons inside an Ajax.BeginForm?

如何将控制器处理每个单独提交?

How would the controller handle each submit separately?

推荐答案

试试这个,

查看

@model TwoModelInSinglePageModel.RegisterModel
@using (Ajax.BeginForm("DYmanicControllerPage", "Test", FormMethod.Post,null, new { id = "frmSignUp" }))
{ 
  <div>
                <input type="hidden" id="" name="hidden2" id="hdasd" />
                @Html.HiddenFor(m => m.hidden1)
                @Html.LabelFor(m => m.Name)
                @Html.TextBoxFor(m => m.Name)
                @Html.ValidationMessageFor(m => m.Name)
            </div>
            <br />
            <div>
                @Html.LabelFor(m => m.Address)
                @Html.TextBoxFor(m => m.Address)
                @Html.ValidationMessageFor(m => m.Address)
            </div>
            <br />
            <div>
                @Html.LabelFor(m => m.PhoneNo)
                @Html.TextBoxFor(m => m.PhoneNo)
                @Html.ValidationMessageFor(m => m.PhoneNo)
            </div>

 <input type="submit" value="Save"  id="btnSave" name="ButtonType"/>
 <input type="submit" value="Next"  id="btnNext" name="ButtonType" />


}

控制器

  [HttpPost]
        public ActionResult DYmanicControllerPage(RegisterModel model,  string ButtonType)
        {
        if(ButtonType == "Next")
        {
            // Do Next Here
        }
        if (ButtonType == "Save")
        {
            //Do save here
        }
        return JavaScript("REturn anything()");

        }

这篇关于ASP.NET MVC:多使用提交按钮Ajax.BeginForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆