Hi i have one view called Customer.In that view i have one field called Area. I kept one add button near to area. suppose if area is not in the list means i click that add button it open AreaPartialView as popup window.
Now i have one issue in that. That is the data is not passing from partial view to post action method of controller.
My Model
public Nullable AreaID { get; set; }
public string Area { get; set; }
public Nullable CityID{ get; set; }
public string City { get; set; }
My Controller
public ActionResult AreaPartialView()
{
ViewBag.CityID = new SelectList(db.Cities, "CityID", "DisplayName");
return View("AreaPartialView");
}
[HttpPost]
public ActionResult AddAreaInfo(CustomerViewModel objareaVM)
{
var objAreaID = Guid.NewGuid();
ViewBag.CityID = new SelectList(db.Cities, "CityID", "DisplayName", objareaVM.CityID);
@Html.Label("Area" , new { @class = "control-label" })
@Html.TextBoxFor(model => model.Area, new { @class = "form-control", type = "text" ,id ="AreaName"})
@Html.ValidationMessageFor(model => model.Area)
@Html.Label("City")
@Html.DropDownList("CityID", null, "Select", new { @class = "form-control " })
function SaveArea() {
var Area = $("#AreaName").val();
var CityID = $("#CityID").val();
alert(Area);
var AreaAdd = {
"AreaName": Area, "CityID": CityID
};
alert(AreaAdd.AreaName);
alert(AreaAdd.CityID);
$.post("/Customer/AddAreaInfo", AreaAdd,
function (data) { if (data == 0) { location = location.href; } }, 'json').success(function (data) {
alert("success");
//window.close();
});
}
if i click the add button Area partial view will open as popup window and if i enter the details and click Create button it get the values and showing all alert messages. But the problem is it does not pass the Area value to post action method it pass the City ID value but it doesn't pass the Area value to post method. The Area value will be always null.
Please any one cross check my code and tell me the solution .
Advance Thanks..
8 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Shuvojit Halder it getting the value in var AreaAdd but when i pass these two values to controller the Area value will be null but not city . this is the issue.
Shuvojit i gave my id as AreaName and it getting the value var AreaAdd = {
"AreaName": Area, "CityID": CityID
};
alert(AreaAdd.AreaName);
alert(AreaAdd.CityID); it shows the both alert message with the values which i enter but it pass the values to post action method the area value will be null but not cityID
Sneha KPosted Mar 21, 2016, 5:08 AM
Shuvojit HalderPosted Mar 21, 2016, 4:51 AM
Sneha KPosted Mar 21, 2016, 4:47 AM
Sneha KPosted Mar 21, 2016, 4:34 AM
Sneha KPosted Mar 21, 2016, 4:34 AM
Shuvojit HalderPosted Mar 21, 2016, 4:26 AM
Sneha KPosted Mar 21, 2016, 4:00 AM
Shuvojit HalderPosted Mar 21, 2016, 3:54 AM