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
Partho Rocko
NA
10
2k
how to get dropdownlist selected value on controller action
Aug 20 2016 5:34 AM
//Model
public class ObjectModel
{
[Required(ErrorMessage = "Please Select District")]
[Display(Name = "Select District")]
public IList<SelectListItem> DistrictNamesModel { get; set; }
public int DistrictId { get; set; }
}
//View
@model MVCtrendsetters.Models.ObjectModel
@{
ViewBag.Title = "Insert";
}
<h2>Insert</h2>
@using (Html.BeginForm("Insert", "AppForm", FormMethod.Post, new { @enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>ObjectModel</legend>
<div>
@Html.DropDownListFor(x => x.DistrictNamesModel, Model.DistrictNamesModel , "--Select--", new { @id = "ddlDistrict"});
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
//Controller
ObjectModel OM = new ObjectModel();
DB dd = new DB();
DataSet ds = new DataSet();
ds = dd.getAllDistrict();
List<SelectListItem> DistrictNames = new List<SelectListItem>();
foreach (DataRow item in ds.Tables[0].Rows)
{
DistrictNames.Add(new SelectListItem { Text = item["CityName"].ToString(), Value = (item["Id"].ToString()) });
}
OM.DistrictNamesModel = DistrictNames;
return View(OM);
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Insert(ObjectModel OM , string DistrictId)
{
return View(OM);
}
Myy question Is How will i get DistrictId in [Httpost] Insert method.. I used a dropdown which is filled correctly. My table has Column Name City adn Id....PLEASE HELP....I will be really thankful
Reply
Answers (
4
)
ebs payment gateway integration in .net c#
post-with-multiple-images-using-asp-net-mvc-get-data-on-post