dropdownlistfor

MVC DropDownListFor

纵然是瞬间 提交于 2021-01-29 03:16:25
问题 I am new using MVC approach. How to using the DropDownListfor in the MVC? I need get the list from my master table and show the option into the Business Premise in the Business Profile object. This is my ViewModel public class SMEAppViewModel { public WP2PBusinessProfile BuisinessProfile { get; set; } public IEnumerable<WP2PMasterDropDownList> MasterList { get; set; } } In my controller, I already initialize the MasterList to the List var _MasterList = _context.WP2PMasterDropDownList.ToList()

asp .net mvc 5 dropdownlist SelectList no validation attributes

﹥>﹥吖頭↗ 提交于 2020-03-16 08:59:34
问题 Inside model I have data annotations: [Required(ErrorMessageResourceName = "SelectCategory", ErrorMessageResourceType = typeof(MyProject.Properties.Resources)), Range(1, int.MaxValue, ErrorMessageResourceName = "SelectCategory", ErrorMessageResourceType = typeof(MyProject.Properties.Resources))] public int CategoryId { get; set; } public virtual Category Category { get; set; } and two situations: Situation1 Inside controller I have List<Category> categories = db.GetCategories(); ViewBag

SelectedItem for multiple DropDownListFor not being selected

流过昼夜 提交于 2020-01-07 06:33:24
问题 I have multiple DropDownListFor's and the selected item is not showing up. The variable storing the selected item is populated correctly. Heres the code Models View Model public class StepFourView { #region Public Properties public IEnumerable<PulldownItem> Levels { get; set; } public IEnumerable<PulldownItem> Approaches { get; set; } public IEnumerable<PulldownItem> Types { get; set; } public StepFour StepFour{ get; set; } #endregion } StepFourModel [Table(Name = "StepFours")] public class

Dropdown list mvc5 from other model

女生的网名这么多〃 提交于 2019-12-25 03:09:17
问题 First time using MVC to develop an app and have run into an issues populating a dropdown in the student create view with a list of teachers. I have 2 models public class Student { [Required] [Display(Name = "ID")] public int ID { get; set; } [Required] [StringLength(100)] [DataType(DataType.Text)] [Display(Name = "First Name")] public string FirstName { get; set; } [Required] [StringLength(100)] [DataType(DataType.Text)] [Display(Name = "Last Name")] public string LastName { get; set; }

The ViewData item that has the key 'CategoryId' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'.

夙愿已清 提交于 2019-12-24 16:56:08
问题 Can you please help with the error below? What is wrong with my codes. Thanks for your help. Error: The ViewData item that has the key 'CategoryId' is of type 'System.Int32' but must be of type 'IEnumerable'. controller public ActionResult ProductCreate() { ViewBag.Suppliers = db.Suppliers.Where(x => x.IsActive).ToList(); ViewBag.Categories = new SelectList(db.Categories.Where(x => x.IsActive).ToList(), "Id", "Name").ToList(); return View(); } [HttpPost] [ValidateAntiForgeryToken] public

The ViewData item that has the key 'CategoryId' is of type 'System.Int32' but must be of type 'IEnumerable<SelectListItem>'.

白昼怎懂夜的黑 提交于 2019-12-24 16:55:03
问题 Can you please help with the error below? What is wrong with my codes. Thanks for your help. Error: The ViewData item that has the key 'CategoryId' is of type 'System.Int32' but must be of type 'IEnumerable'. controller public ActionResult ProductCreate() { ViewBag.Suppliers = db.Suppliers.Where(x => x.IsActive).ToList(); ViewBag.Categories = new SelectList(db.Categories.Where(x => x.IsActive).ToList(), "Id", "Name").ToList(); return View(); } [HttpPost] [ValidateAntiForgeryToken] public

@Html.DropDownListFor; How to set different background color for each item in DDL?

独自空忆成欢 提交于 2019-12-20 03:44:09
问题 I have a dropdown list (@html.DropDownListFor) wherein I am showing name of colors... I want to display each item having seperate background color.. Like, an item "Green" should be in green background, and "Yellow" in yellow background. How can I achieve this? 回答1: Don't forget that you can always write old fashioned HTML in a view (OMG!). But, if you are using the code in multiple places, then write a helper that extends DropDownListFor to create your select with styling. If you are using it

Remove AutoCompleteTextView dropdown list divider

99封情书 提交于 2019-12-19 22:04:56
问题 In my application, I'm using AutoCompleteTextView. One of the requirements is to hide the divider. I have added AutoCompleteTextView to layout: <AutoCompleteTextView android:id="@id/address_bar" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="15dp" android:layout_marginRight="8dp" android:layout_toLeftOf="@id/address_operation_btn" android:background="@null" android:completionThreshold="1" android:dropDownAnchor="@id/anchor" android

How to use a ViewBag to create a dropdownlist?

爱⌒轻易说出口 提交于 2019-12-17 23:22:25
问题 Controller: public ActionResult Filter() { ViewBag.Accounts = BusinessLayer.AccountManager.Instance.getUserAccounts(HttpContext.User.Identity.Name); return View(); } View: <td>Account: </td> <td>@Html.DropDownListFor("accountid", new SelectList(ViewBag.Accounts, "AccountID", "AccountName"))</td> ViewBag.Accounts contains Account objects which have AccountID , AccountName and other properties. I would like a DropDownList called accountid (so that on Form Post I can pass the selected AccountID)

MVC DropDownListFor default value for bool

血红的双手。 提交于 2019-12-13 17:05:58
问题 I have a dropdownlistfor with True/False values. I want the default value to be true. Right now it's false because the default of a bool is false. This dropdown sometimes gets created dynamically in javascript so I can't set the value in the model before it gets passed. How do I set the default to True in the chtml file? Thank you. //---------- cshtml file --------------- ... <td class="valuebool"> @Html.DropDownListFor(m => m.IsBoolFilterCondition, new SelectList( new[] { // The following