Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.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
Jquery 部分视图的Ajax.actionLink输入值不会与主机视图一起发布_Jquery_Ajax_Asp.net Mvc - Fatal编程技术网

Jquery 部分视图的Ajax.actionLink输入值不会与主机视图一起发布

Jquery 部分视图的Ajax.actionLink输入值不会与主机视图一起发布,jquery,ajax,asp.net-mvc,Jquery,Ajax,Asp.net Mvc,我已经找了两天多的答案了,请有人帮忙 我有一个“创建”视图,可以在其中预订餐厅。在视图上,您必须能够创建新来宾或选择现有来宾。默认情况下,您可以在视图中选择现有来宾,如果来宾不在,则可以单击ajax.actionlink以呈现局部视图来创建新来宾。选择当前客人或填写新客人的字段后,您将继续预订。最后单击“创建” 我的目标是将部分视图的字段和保留字段(主机视图)一起发布到“创建”控制器,但问题是模型绑定器没有绑定部分视图的输入字段,因此我无法将新来宾和新保留一起立即保存到数据库。我使用的是asp.

我已经找了两天多的答案了,请有人帮忙

我有一个“创建”视图,可以在其中预订餐厅。在视图上,您必须能够创建新来宾或选择现有来宾。默认情况下,您可以在视图中选择现有来宾,如果来宾不在,则可以单击ajax.actionlink以呈现局部视图来创建新来宾。选择当前客人或填写新客人的字段后,您将继续预订。最后单击“创建”

我的目标是将部分视图的字段和保留字段(主机视图)一起发布到“创建”控制器,但问题是模型绑定器没有绑定部分视图的输入字段,因此我无法将新来宾和新保留一起立即保存到数据库。我使用的是asp.net mvc5

主“创建”视图

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>BistroReservations_Reservation</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.DateOfArrival, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DateOfArrival, new { htmlAttributes = new { @class = "form-control datecontrol" } })
                @Html.ValidationMessageFor(model => model.DateOfArrival, "", new { @class = "text-danger" })
            </div>
        </div>

        ...

    <div class="form-group">
        @Html.LabelFor(model => model.BistroReservations_GuestID, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-6">
            @Html.DropDownList("BistroReservations_GuestID", null, htmlAttributes: new { @class = "form-control" })     
            @Html.ValidationMessageFor(model => model.BistroReservations_GuestID, "", new { @class = "text-danger " })

            @Ajax.ActionLink("Create a New Guest", "NewGuest", new AjaxOptions()
           {
               HttpMethod = "GET",
               UpdateTargetId = "NewGuest",
               InsertionMode = InsertionMode.ReplaceWith,               
           })              
        </div>
    </div>       

        <div id="NewGuest" class="form-group">
        </div>

        ...

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}
@using (Html.BeginForm()) 
    {


        <div class="form-horizontal">            
            <hr />    
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })

            <div class="form-group">
                @Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.MobileNumber, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.MobileNumber, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.MobileNumber, "", new { @class = "text-danger" })
                </div>
            </div>    

            <div class="form-group">
                @Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
                </div>
            </div>            
        </div>
    <hr />    
   }   
public partial class BistroReservations_Reservation
{


    public int BistroReservations_ReservationID { get; set; }

    [Display(Name="Day Of Reservations")]
    [Required]
    [DataType(DataType.Date)]
    public DateTime DateOfArrival { get; set; }

    public int BistroReservations_ShiftID { get; set; }
    public BistroReservations_Shift BistroReservations_Shift { get; set; }

    public int BistroReservations_GuestID { get; set; }
    public virtual BistroReservations_Guest BistroReservations_Guest { get; set; }

    [Required]
    [Display(Name = "Arrival Time")]
    public int BistroReservations_TimeID { get; set; }
    public virtual BistroReservations_Time ArrivalTime { get; set; }

    [Required]    
    [Display(Name="Departure Time")]        
    public virtual BistroReservations_Time DepartureTime { get; set; }   

    [Display(Name="Location")]
    public int LocationID { get; set; }
    public virtual BistroReservations_Location BistroReservations_Location { get; set; }

    [Display(Name="Type Of Seating")]
    public int BistroReservations_TypeOfSeatingID { get; set; }
    public virtual BistroReservations_TypeOfSeating BistroReservations_TypeOfSeating { get; set; }

    [Display(Name="Table Number")]
    public int TableNoID { get; set; }
    public virtual BistroReservations_TableNo BistroReservations_TableNo { get; set; }

    [Display(Name="Status")]
    public int BistroReservations_StatusID { get; set; }
    public virtual BistroReservations_Status BistroReservations_Status { get; set; }

    public virtual BistroReservations_ArrivalStatus BistroReservations_ArrivalStatus { get; set; }

    [Display(Name="Comments")]
    public string Comment { get; set; }

    public DateTime DateAdded { get; set; }

    public string UserID  { get; set; }
    public virtual User User { get; set; }

    public virtual List<BistroReservations_ReservationFurniture> BistroReservations_ReservationFurniture { get; set; }
public class BistroReservations_Guest
{
    public int BistroReservations_GuestID { get; set; }

    [Display(Name = "Mobile Number")]        
    public string MobileNumber { get; set; }

    [Required]
    [Display(Name="First Name")]
    public string FirstName { get; set; }

    [Required]
    [Display(Name = "Last Name")]
    public string LastName { get; set; }

    [Required]
    [Display(Name="E-mail Address")]
    [EmailAddress]
    public string Email { get; set; }

    public virtual List<BistroReservations_Reservation> BistroReservations_Reservation { get; set; }
}
我的主视图模型

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>BistroReservations_Reservation</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.DateOfArrival, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DateOfArrival, new { htmlAttributes = new { @class = "form-control datecontrol" } })
                @Html.ValidationMessageFor(model => model.DateOfArrival, "", new { @class = "text-danger" })
            </div>
        </div>

        ...

    <div class="form-group">
        @Html.LabelFor(model => model.BistroReservations_GuestID, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-6">
            @Html.DropDownList("BistroReservations_GuestID", null, htmlAttributes: new { @class = "form-control" })     
            @Html.ValidationMessageFor(model => model.BistroReservations_GuestID, "", new { @class = "text-danger " })

            @Ajax.ActionLink("Create a New Guest", "NewGuest", new AjaxOptions()
           {
               HttpMethod = "GET",
               UpdateTargetId = "NewGuest",
               InsertionMode = InsertionMode.ReplaceWith,               
           })              
        </div>
    </div>       

        <div id="NewGuest" class="form-group">
        </div>

        ...

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}
@using (Html.BeginForm()) 
    {


        <div class="form-horizontal">            
            <hr />    
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })

            <div class="form-group">
                @Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.MobileNumber, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.MobileNumber, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.MobileNumber, "", new { @class = "text-danger" })
                </div>
            </div>    

            <div class="form-group">
                @Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
                </div>
            </div>            
        </div>
    <hr />    
   }   
public partial class BistroReservations_Reservation
{


    public int BistroReservations_ReservationID { get; set; }

    [Display(Name="Day Of Reservations")]
    [Required]
    [DataType(DataType.Date)]
    public DateTime DateOfArrival { get; set; }

    public int BistroReservations_ShiftID { get; set; }
    public BistroReservations_Shift BistroReservations_Shift { get; set; }

    public int BistroReservations_GuestID { get; set; }
    public virtual BistroReservations_Guest BistroReservations_Guest { get; set; }

    [Required]
    [Display(Name = "Arrival Time")]
    public int BistroReservations_TimeID { get; set; }
    public virtual BistroReservations_Time ArrivalTime { get; set; }

    [Required]    
    [Display(Name="Departure Time")]        
    public virtual BistroReservations_Time DepartureTime { get; set; }   

    [Display(Name="Location")]
    public int LocationID { get; set; }
    public virtual BistroReservations_Location BistroReservations_Location { get; set; }

    [Display(Name="Type Of Seating")]
    public int BistroReservations_TypeOfSeatingID { get; set; }
    public virtual BistroReservations_TypeOfSeating BistroReservations_TypeOfSeating { get; set; }

    [Display(Name="Table Number")]
    public int TableNoID { get; set; }
    public virtual BistroReservations_TableNo BistroReservations_TableNo { get; set; }

    [Display(Name="Status")]
    public int BistroReservations_StatusID { get; set; }
    public virtual BistroReservations_Status BistroReservations_Status { get; set; }

    public virtual BistroReservations_ArrivalStatus BistroReservations_ArrivalStatus { get; set; }

    [Display(Name="Comments")]
    public string Comment { get; set; }

    public DateTime DateAdded { get; set; }

    public string UserID  { get; set; }
    public virtual User User { get; set; }

    public virtual List<BistroReservations_ReservationFurniture> BistroReservations_ReservationFurniture { get; set; }
public class BistroReservations_Guest
{
    public int BistroReservations_GuestID { get; set; }

    [Display(Name = "Mobile Number")]        
    public string MobileNumber { get; set; }

    [Required]
    [Display(Name="First Name")]
    public string FirstName { get; set; }

    [Required]
    [Display(Name = "Last Name")]
    public string LastName { get; set; }

    [Required]
    [Display(Name="E-mail Address")]
    [EmailAddress]
    public string Email { get; set; }

    public virtual List<BistroReservations_Reservation> BistroReservations_Reservation { get; set; }
}
公共部分类BistroReservations\u保留
{
public int BistroReservations_ReservationID{get;set;}
[显示(Name=“预订日期”)]
[必需]
[数据类型(DataType.Date)]
公共日期时间到达日期{get;set;}
public int BistroReservations_ShiftID{get;set;}
公共BistroReservations\u Shift BistroReservations\u Shift{get;set;}
public int BistroReservations_GuestID{get;set;}
公共虚拟BistroReservations_Guest BistroReservations_Guest{get;set;}
[必需]
[显示(Name=“到达时间”)]
public int BistroReservations_TimeID{get;set;}
公共虚拟BistroReservations\u时间到达时间{get;set;}
[必需]
[显示(Name=“出发时间”)]
公共虚拟BistroReservations\u Time DepartureTime{get;set;}
[显示(名称=“位置”)]
public int LocationID{get;set;}
公共虚拟BistroReservations\u Location BistroReservations\u Location{get;set;}
[显示(名称=“座位类型”)]
public int BistroReservations_TypeOfSeatingID{get;set;}
公共虚拟BistroReservations\u类型存储BistroReservations\u类型存储{get;set;}
[显示(名称=“表格编号”)]
公共int TableNoID{get;set;}
公共虚拟BistroReservations\u TableNo BistroReservations\u TableNo{get;set;}
[显示(Name=“Status”)]
public int BistroReservations_StatusID{get;set;}
公共虚拟BistroReservations_Status BistroReservations_Status{get;set;}
公共虚拟BistroReservations_ArrivalStatus BistroReservations_ArrivalStatus{get;set;}
[显示(Name=“注释”)]
公共字符串注释{get;set;}
public DateTime DateAdded{get;set;}
公共字符串用户标识{get;set;}
公共虚拟用户用户{get;set;}
公共虚拟列表BistroReservations\u ReservationFurniture{get;set;}
我的局部视图模型

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()

    <div class="form-horizontal">
        <h4>BistroReservations_Reservation</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.DateOfArrival, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DateOfArrival, new { htmlAttributes = new { @class = "form-control datecontrol" } })
                @Html.ValidationMessageFor(model => model.DateOfArrival, "", new { @class = "text-danger" })
            </div>
        </div>

        ...

    <div class="form-group">
        @Html.LabelFor(model => model.BistroReservations_GuestID, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-6">
            @Html.DropDownList("BistroReservations_GuestID", null, htmlAttributes: new { @class = "form-control" })     
            @Html.ValidationMessageFor(model => model.BistroReservations_GuestID, "", new { @class = "text-danger " })

            @Ajax.ActionLink("Create a New Guest", "NewGuest", new AjaxOptions()
           {
               HttpMethod = "GET",
               UpdateTargetId = "NewGuest",
               InsertionMode = InsertionMode.ReplaceWith,               
           })              
        </div>
    </div>       

        <div id="NewGuest" class="form-group">
        </div>

        ...

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="submit" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}
@using (Html.BeginForm()) 
    {


        <div class="form-horizontal">            
            <hr />    
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })

            <div class="form-group">
                @Html.LabelFor(model => model.FirstName, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.FirstName, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.FirstName, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.LastName, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.LastName, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.LastName, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.MobileNumber, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.MobileNumber, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.MobileNumber, "", new { @class = "text-danger" })
                </div>
            </div>    

            <div class="form-group">
                @Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
                </div>
            </div>            
        </div>
    <hr />    
   }   
public partial class BistroReservations_Reservation
{


    public int BistroReservations_ReservationID { get; set; }

    [Display(Name="Day Of Reservations")]
    [Required]
    [DataType(DataType.Date)]
    public DateTime DateOfArrival { get; set; }

    public int BistroReservations_ShiftID { get; set; }
    public BistroReservations_Shift BistroReservations_Shift { get; set; }

    public int BistroReservations_GuestID { get; set; }
    public virtual BistroReservations_Guest BistroReservations_Guest { get; set; }

    [Required]
    [Display(Name = "Arrival Time")]
    public int BistroReservations_TimeID { get; set; }
    public virtual BistroReservations_Time ArrivalTime { get; set; }

    [Required]    
    [Display(Name="Departure Time")]        
    public virtual BistroReservations_Time DepartureTime { get; set; }   

    [Display(Name="Location")]
    public int LocationID { get; set; }
    public virtual BistroReservations_Location BistroReservations_Location { get; set; }

    [Display(Name="Type Of Seating")]
    public int BistroReservations_TypeOfSeatingID { get; set; }
    public virtual BistroReservations_TypeOfSeating BistroReservations_TypeOfSeating { get; set; }

    [Display(Name="Table Number")]
    public int TableNoID { get; set; }
    public virtual BistroReservations_TableNo BistroReservations_TableNo { get; set; }

    [Display(Name="Status")]
    public int BistroReservations_StatusID { get; set; }
    public virtual BistroReservations_Status BistroReservations_Status { get; set; }

    public virtual BistroReservations_ArrivalStatus BistroReservations_ArrivalStatus { get; set; }

    [Display(Name="Comments")]
    public string Comment { get; set; }

    public DateTime DateAdded { get; set; }

    public string UserID  { get; set; }
    public virtual User User { get; set; }

    public virtual List<BistroReservations_ReservationFurniture> BistroReservations_ReservationFurniture { get; set; }
public class BistroReservations_Guest
{
    public int BistroReservations_GuestID { get; set; }

    [Display(Name = "Mobile Number")]        
    public string MobileNumber { get; set; }

    [Required]
    [Display(Name="First Name")]
    public string FirstName { get; set; }

    [Required]
    [Display(Name = "Last Name")]
    public string LastName { get; set; }

    [Required]
    [Display(Name="E-mail Address")]
    [EmailAddress]
    public string Email { get; set; }

    public virtual List<BistroReservations_Reservation> BistroReservations_Reservation { get; set; }
}
public class BistroReservations\u Guest
{
public int BistroReservations_GuestID{get;set;}
[显示(Name=“手机号码”)]
公共字符串MobileNumber{get;set;}
[必需]
[显示(Name=“First Name”)]
公共字符串名{get;set;}
[必需]
[显示(Name=“Last Name”)]
公共字符串LastName{get;set;}
[必需]
[显示(Name=“电子邮件地址”)]
[电邮地址]
公共字符串电子邮件{get;set;}
公共虚拟列表BistroReservations_Reservation{get;set;}
}

没有
代码的问题是令人头痛的!我很抱歉,我现在添加了它,我对此很陌生,请原谅。您是否为您的主视图和部分视图声明了
@model
?如果是,是什么?@Jason,是的,我两个都有模型,我更新了主问题。谢谢。我看到的一个问题是您正在嵌套表单:一个用于主视图,另一个用于局部视图。应删除局部视图的
BeginForm