Hello,
I m trying to set dropdown value in edit mode from model, but not able to do that,
Please help.
my code is as per below.
View
@model AdminPortal.Models.UserModel
@{
}
$(function () {
valueChanged();
$('.datepicker').datepicker({
autoclose: true
})
debugger;
var ddlDesignation = $("#ddlDesignationId");
debugger;
$.ajax({
type: "POST",
url: "/User/PopulateDesignation",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
ddlDesignation.empty().append('');
$.each(response, function () {
ddlDesignation.append($("").val(this['Value']).html(this['Text']));
});
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
});
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
HtmlHelper.UnobtrusiveJavaScriptEnabled = false;
@Html.DropDownListFor(Model => Model.DesignationId, new List
{
}, htmlAttributes: new { @class = "form-control", id = "ddlDesignationId" })
}
In model
public string DesignationId { get; set; }
In Controller
public ActionResult Create(string UserId)
{
//PopulateDesignation();
if (UserId == null)
return View();
else
{
UserDAL userDAL = new UserDAL();
return View(userDAL.GetUsers().Find(umodel => umodel.UserId == UserId));
}
}
public JsonResult PopulateDesignation()
{
List items = new List();
UserDAL userDAL = new UserDAL();
items = userDAL.PopulateDesignation();
return Json(items);
}

Mohammad SbeehPosted Sep 13, 2018, 2:53 AM
Employees List
@item.Name
@item.DepartmentId
Jaykumar SutharPosted Sep 13, 2018, 1:43 AM
Mohammad SbeehPosted Sep 13, 2018, 1:12 AM