TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Jaykumar Suthar
NA
207
16.9k
how to set dropdown value in Edit mode of User Form in MVC.
Sep 10 2018 4:45 AM
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
@{
}
<script type="text/javascript">
$(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('<option selected="selected" value="0">--Select--</option>');
$.each(response, function () {
ddlDesignation.append($("<option></option>").val(this['Value']).html(this['Text']));
});
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
});
</script>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
HtmlHelper.UnobtrusiveJavaScriptEnabled = false;
<label for="Designation">Designation</label>
@Html.DropDownListFor(Model => Model.DesignationId, new List<SelectListItem>
{
}, 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<SelectListItem> items = new List<SelectListItem>();
UserDAL userDAL = new UserDAL();
items = userDAL.PopulateDesignation();
return Json(items);
}
Reply
Answers (
3
)
Xamarin - How to TextView Information with Justify Alignment
font is not clear while taking printout in rdlc report