Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC按钮未触发ActionResult_C#_Jquery_Asp.net Mvc_Model View Controller - Fatal编程技术网

C# MVC按钮未触发ActionResult

C# MVC按钮未触发ActionResult,c#,jquery,asp.net-mvc,model-view-controller,C#,Jquery,Asp.net Mvc,Model View Controller,最近我开始研究MVC应用程序,到目前为止我一直在研究这个 我有这个.cshtml代码: @model Vidly.ViewModels.NewCustomerViewModel @{ ViewBag.Title = "NewCustomer"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>New Customer</h2> @using (Html.BeginForm("Save", "Custome

最近我开始研究MVC应用程序,到目前为止我一直在研究这个

我有这个.cshtml代码:

@model Vidly.ViewModels.NewCustomerViewModel
@{
    ViewBag.Title = "NewCustomer";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>New Customer</h2>

@using (Html.BeginForm("Save", "Customers",FormMethod.Post,null))
{

    <form class="form-group">
        @Html.LabelFor(m => m.Customer.Name)
        @Html.TextBoxFor(m => m.Customer.Name, new { @class = "form-control" })
    </form>
    <form class="form-group">
        @Html.LabelFor(m => m.Customer.Birthdate)
        @Html.TextBoxFor(m => m.Customer.Birthdate, new { @class = "form-control" })
    </form>
    <form class="checkbox">
        <label>
            @Html.CheckBoxFor(m => m.Customer.IsSubscribedToNewsletter, new { @class = "form-control" }) Subscribed to Newsletter
        </label>
    </form>
    <form class="form-group">
        @Html.LabelFor(m => m.Customer.MembershipTypeId)
        @Html.DropDownListFor(m => m.Customer.MembershipType, new SelectList(Model.MembershipTypes, "Id", "Name"), "Select Membership Type", new { @class = "form-control" })
    </form>
    @Html.HiddenFor(m => m.Customer.Id)
    <button type="submit" class="btn btn-primary">Save</button>   
}
问题是,当我尝试单击Save按钮时,它根本不会触发SaveActionResult。 我已经尝试在调试模式下启动,并在代码上设置断点,但实际上并没有触发该方法。 我已经读到它与在ActionResult之前触发的JQuery事件有关,但我不知道如何阻止它(如果JQuery真的与此有关)


有什么想法吗?拜托,我真的被困在这上面了

视图中的模型是
newCustomerServiceWModel
,因此绑定到的模型必须相同(或者需要使用
BindAttribute
前缀
属性)

将方法的签名更改为

public ActionResult Save(NewCustomersViewModel model)
此外,您还需要删除所有
元素(由
生成的元素除外),因为嵌套表单是无效的html


但是,代码表明视图模型包含
客户
数据模型的属性,这是一种不好的做法。视图模型应仅包含视图中所需的数据模型的属性。然后将视图模型的属性映射到数据模型。

不相关,但不能在表单中嵌套表单,这些表单应该是
哦,谢谢!对不起,弄错了!在这个话题上我真的是个新手。会发生什么?如果您监视浏览器的网络选项卡,单击该按钮会为请求生成什么?它根本没有生成任何请求,它只是在做一些文字上的工作,它工作正常!!!谢谢你,伙计,我已经实现了你的提示,现在按钮就像火箭发射器一样发射!非常感谢你!
public ActionResult Save(NewCustomersViewModel model)