MVC提交按钮不起作用

时间:2016-05-15 01:46:11

标签: asp.net-mvc button submit

“提交”按钮不会调用控制器中的方法来保存数据,而是调用方法用于加载页面。我的守则如下。我确实试过Html.BeginForm("ServiceEntryRegister","",FormMethod.Post)

public class ServiceEntryRegister
{
    public List<ReceiptHeader> HEADER { get; set; }
    public List<ReceiptDetail> DETAIL { get; set; }
    public ReceiptHeader SingleHEADER { get; set; }
    public ReceiptDetail SingleDETAIL { get; set; }
    public List<Suburb> SUBURB { get; set; }
}

控制器:

public class ServiceEntryRegisterController : Controller
{

    private AUTOEntities _er = new AUTOEntities();
    private DateTime _Defaultdate = Convert.ToDateTime("01/01/1900 00:00:00");

    public ActionResult Index(DateTime P_ServiceDate , String P_Registraion="x", String P_CustomerName="x")
    {
        var Model = new ServiceEntryRegister();
        if(P_ServiceDate!=null || P_Registraion!=null || P_CustomerName!=null)
        {
        }        
        return View();
    }

    public ActionResult CreateNew()
    {
        CreateBagForLists();
        var Model = new ServiceEntryRegister();
        return View(Model);
    }

    [HttpPost]
    private ActionResult CreateNew(ServiceEntryRegister RH,String save)
    {
        if (ModelState.IsValid)
        {
            int x = 0;
            x++;
            return View();
        }
        else
        {
            return View();
        }
    }
}

查看:

@model HIMA_AUTOWORKSHOP.Models.ServiceEntryRegister
@using (Html.BeginForm())
{
    <table>
        <td>
            <table>
                <th> </th>
                <th></th>
                <tr>
                    <td>Dated </td>
                    <td>Nil</td>
                </tr>
                <tr>
                    <td>Owner Name</td>
                    <td>@Html.TextBoxFor(o => o.SingleHEADER.OwnerName)</td>
                </tr>
                <tr>
                    <td>Mobile</td>
                    <td>@Html.TextBoxFor(w => w.SingleHEADER.Mobile, null, new { maxlength = 10, autocomplete = "on", style = "width:245px" })</td>
                <tr>
                    <td></td>
                    <td><input name="submit" type="submit" id="submit" value="Save Request" /></td>
                </tr>
            </table> 
        </td>
    </table>
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

1 个答案:

答案 0 :(得分:2)

如果该方法是私有的,那么您的发布请求将永远不会调用该方法。但是既然你没有将无参数方法标记为HttpGet,那就是它被调用的原因