html.dropdownlistfor

Selected value in asp.net MVC 4.0 dropdownlist

谁说胖子不能爱 提交于 2019-11-30 06:00:00
问题 I am trying to make a dropdown list using DropdownListFor function and I want to have a value selected in it. I have searched a lot and found the similar kind of solution of having a SelectList object in the ViewModel , I tried it something like this In my ViewModel I used a property of type SelectList like this SelectList HoursToSelect = new SelectList(MyDictionaryObject, "Value", "Key", 14/*selected value*/); and I was using it like this @Html.DropDownListFor(m => m.EndsOnHour,

create many DropDownListFor in foreach-loop [duplicate]

隐身守侯 提交于 2019-11-30 03:26:36
问题 This question already has answers here : DropDownListFor does not select value if in for loop (6 answers) How to set default value to select list in MVC during run time (2 answers) Closed 3 years ago . I want to create DropDownLists dynamically out of a List, which supplies the SelectList and a field where to save the selection. public class ViewModel { public List<Material_Select> materialSelect { get; set; } } public class Material_Select { public SelectList selectList { get; set; } public

DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a property with the name 'CategoryTypeID'

隐身守侯 提交于 2019-11-30 01:22:48
问题 I am using MVC. I want to pass the category data I entered from my view and passed to my Post/ Createcontroller, but it's not's letting me pass my categoryTypeID that I have selected from my dropdownlist. Here is the error: DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a property with the name 'CategoryTypeID'. Here is my code: My CreateController: // // POST: /Category/Create [HttpPost] public ActionResult Create(Category category) { if (ModelState.IsValid) { db.Categories

How to create ASP.Net MVC DropDownList with required validation

£可爱£侵袭症+ 提交于 2019-11-29 12:07:10
I working with mvc 5. I am loading data from Database Using ORM and fill a drop down list from the controller, like this. ViewBag.Country_id = new SelectList(_db.Countries, "Country_id", "Description"); As i wanted an empty field first I am doing this in my HTML. <div class="form-group"> @Html.LabelFor(model => model.Countries, "Country", htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.DropDownList("Country_id", null, htmlAttributes: new { @class = "form-control" }, optionLabel: "Choose a Country") @Html.ValidationMessageFor(model => model.Country_id, "

How to use MVC Html Helper .DropDownListFor<> with an Enum

百般思念 提交于 2019-11-29 09:54:46
问题 In my MVC 3 Razor app, I have a Model with an enum.. Model Example: public class EmployeeModel { public enum Title { Accountant = 111, Sales = 222, Production = 333 } [Required] public string Name {get; set;} [Required] public Title JobTitle {get; set;} } In my View I would like to use the Html helpers to build an Html Form... View Example: @model ..Models.EmployeeModel @using (Html.BeginForm()) { @Html.LabelFor(m => m.Name) @Html.TextBoxFor(m => m.Name) <br> @Html.LabelFor(m => m.JobTitle)

Apply filtering to generate a dropdown list

老子叫甜甜 提交于 2019-11-29 08:54:30
I have the following class and want to filter the dropdown list based on a certain condition. Model Classes public class Option { public int OptionID { get; set;} public string OptionName { get; set; } public int TechnicalCharacteristicID { get; set; } public int LsystemID { get; set; } public virtual ICollection<OptionValue> OptionValues { get; set; } public virtual TechnicalCharacteristic TechnicalCharacteristic { get; set; } public virtual Lsystem Lsystem { get; set; } } public class OptionValue { public int OptionValueID { get; set; } public string OptionVal { get; set; } public int

Get selected item in DropDownList ASP.NET MVC

余生长醉 提交于 2019-11-29 08:41:45
I know there are multiple threads on how to get the selected value of a DropDownList. However I can't find the right way to get this value from a partial view in my controller. This is my partial view: @model List<aptest.Models.answer> @Html.DropDownList("dropdownlist", new SelectList(Model, "text", "text")) <button type="submit">next</button> In order to get dropdown value, wrap your select list in a form tag. Use models and DropDownListFor helper Razor View @model MyModel @using (Html.BeginForm("MyController", "MyAction", FormMethod.Post) { @Html.DropDownListFor(m => m.Gender, MyModel

ASP.NET MVC + Populate dropdownlist

人走茶凉 提交于 2019-11-28 23:44:57
In my viewModel I have: public class PersonViewModel { public Person Person { get; set; } public int SelectRegionId { get; set; } public IEnumerable<SelectListItem> Regions { get; set; } } But what do I have to do in my Controller/View to show the values? What I have now: Controller: public ActionResult Create() { var model = new ReUzze.Models.PersonViewModel { Person = new Person(), Regions = new SelectList(this.UnitOfWork.RegionRepository.Get(), "Id", "Name") }; return View(model); } View: <div class="form-group"> @Html.LabelFor(model => model.Person.Address.Region) @Html.DropDownListFor

Load PartialView with using jquery Ajax?

隐身守侯 提交于 2019-11-28 20:57:24
PartialView @model OsosYeni23072012.Models.TblMeters <h3> Model.customer_name </h3> <h3> Model.meter_name </h3> Controller [HttpGet] public ActionResult MeterInfoPartial(string meter_id) { int _meter_id = Int32.Parse(meter_id); var _meter = entity.TblMeters.Where(x => x.sno == _meter_id).FirstOrDefault(); return PartialView("MeterInfoPartial", _meter); } Razor @Html.DropDownList("sno", new SelectList(Model, "sno", "meter_name"), "-- Select Meter --", new { id = "meters"}) @Html.Partial("MeterInfoPartial") I want to load partial view, if dropdownlist change. But I dont know How can I do this. I

Binding to a DropDownList in MVC3

筅森魡賤 提交于 2019-11-28 14:32:15
Previously, I was using this in my model public List<SelectListItem> StatusList { get; set; } public string Status { get; set; } and this in my view to bind to the Dropdownlist @Html.DropDownListFor(model => model.Status, Model.StatusList, "") but if I want to use public List<ICode> StatusList { get; set; } where ICode is as below public interface ICode { int Id { get; set; } ICodeGroup CodeGroup { get; set; } string ShortDescription { get; set; } string LongDescription { get; set; } } What should I do in my view and model? Cybernate's solution works. You could also do: @Html.DropDownListFor