I have a main view and two partial views
- Index - main view
- _Details - partial view
- _Address- partial view inside the Details partial view
Index - main view
@model IndexViewModel
@{
Layout = "~/Views/Shared/_CodeLayout.cshtml";
}
@Html.Partial("_Details", Model)
2. _Details - partial view
@model IndexViewModel
<div id="Detailsdiv">
@using (Html.BeginForm("_Details", "FS", FormMethod.Post, new
{
id =
"frmFS",
@class = "form-horizontal"
}))
{
<div class="row">
<div class="col-lg-1 nopadding">
<div class="col-lg-1 nopadding">
@Html.LabelFor(m => m.User.Name):
</div>
<div class="col-lg-2">
@Html.TextBoxFor(m => m.User.Name, new { @id = "txtName", @style = "width:140px;height:24px", @maxlength = "25" })
</div>
</div>
</div>
@Html.Action("_Address", "Shared", new { userId = Model.User.UserId })
}
<button type="button" value="Save" ID="btnSave"> Save </button>
}
</div>
3. _Address- partial view
@model AddressViewModel
<div id="divAddress">
@using (Html.BeginForm("_Address", "Shared", FormMethod.Post, new { id = "frmAddress", @class = "form-horizontal" }))
{
<div class="row">
<div class="col-lg-1 nopadding">
@Html.LabelFor(m => m.Address.AddressDesc):
</div>
<div class="col-lg-2">
@Html.TextBoxFor(m => m.Address.AddressDesc, new { @id = "txtAName", @style = "width:140px;height:24px", @maxlength = "25" })
</div>
</div>
---
-
-
And some more
<button type="button" value="Save" ID="btnCreate"> Create </button>
</div>
}
$('#btnCreate').click(function () {
$("#ajax_loader").show();
var inputdata = $("#frmAddress").serialize();
$.ajax({
url: '@Url.Action("CreateAddress", "Shared")',
type: 'POST',
cache: false,
data: inputdata
}).done(function (result) {
$("#divAddress").html(result);
$("#ajax_loader").hide();
});
});
SharedConroller
Get Action for Address
public ActionResult _ Address (short userId )
{
}
public ActionResult CreateAdderess(AddressViewModel addressViewModel)
{
Create address…………..
But AddressViewModel is coming null
}
}
public class AddressViewModel
{
[Key]
public decimal AddressId { get; set; }
[DisplayName("Address Type")]
public string Addr_Typ { get; set; }
[DisplayName("Address Description")]
[MaxLength(256)]
public string Addr_Desc { get; set; }
[DisplayName("City")]
[MaxLength(30)]
public string City_Nm { get; set; }
[DisplayName("State")]
[MaxLength(2)]
public string State_Cd { get; set; }
[DisplayName("Zip")]
[RegularExpression(@"^\d{5}(?:[\-]?\d{4})?$", ErrorMessage = "Invalid Zip")]
[MaxLength(10)]
public string Zip { get; set; }
}
Post back from the _Details is working. Post back from the Address- partial view is not working.
Thanks in advance