html.dropdownlistfor

Dashless GUID not used DropDownListFor

这一生的挚爱 提交于 2019-12-24 13:50:12
问题 I have a page, which accepts a parameter x (which is a GUID). On the page I have a HTML.DropDownListFor(x => x.SomeGuidProperty). If I specify parameter x in URL as 43f67d68-066d-4fda-94a8-3e3e4c7c278a (with dashes), drop down selects respeced option. But if I specify parameter x in URL as 43f67d68066d4fda94a83e3e4c7c278a (still GUID, but no dashes) - DropDownList ignores it. It is impossible to ensure single format of GUID, as page is used by different sources. What can be done to make

ASP.NET MVC 3 Dropdownlist of Users

梦想的初衷 提交于 2019-12-24 10:55:30
问题 In my application I have associated my UserId to a table in my database. I need that when I create a new item I can choose the user name from a dropdownlist. And 'possible to do this with the element viewbag? @Html.EditorFor(model => model.UserId) I use default membership provider so I can't use Entity Framework for this problem EDIT EDIT 2 This is my action create: [HttpPost] public ActionResult Create(Employe employe) { var users = Roles.GetUsersInRole("Admin"); SelectList list = new

Remove blank/empty entry at top of EnumDropDownListFor box

老子叫甜甜 提交于 2019-12-23 07:55:27
问题 I am rendering a drop down list box using my enums and I only have 3 options, but for some reason it is displaying four. The top and default option is simply blank/empty and I want this removed. I want the top/default value to be 'Option1'. Enums: public enum EventType { [Display(Name = "Option 1")] Option1, [Display(Name = "Option 2")] Option2, [Display(Name = "Option 3")] Option3 } View: @Html.EnumDropDownListFor(model => model.EventType, null, new { @id = "eventType", @class = "form

How to dynamic bind html.DropDownList() in MVC

删除回忆录丶 提交于 2019-12-23 04:38:17
问题 I have a dropdownlist and a textbox in my page,I want to change the dropdownlist with the textbox change. I use JQuery post like this: $("#txtBuildId").change(function() { var builddate = $("#txtBuildId").val(); $.post("/UTOverview/Index?builddate=" + builddate); }); and my Index function is: public ActionResult Index() { string buildDate = Request.Params.Get("builddate"); DataTable tbBuildid = DatabaseService.getBuilidByDate(buildDate); List<SelectListItem> list = new List<SelectListItem>();

MVC3 dropdownlistfor

僤鯓⒐⒋嵵緔 提交于 2019-12-22 08:59:12
问题 I would like to make a dropdown list, with the numbers 0-10. So users can rate something. At the moment, I have a label: @Html.LabelFor(model=> model.RATE) How can I modify this code that I will have a dropdown box? And that the value of the dropdown box will be stored in model.RATE? The label is working, but it would be much better to have a dropdown menu. SOLUTION: @Html.DropDownListFor(model => model.RATE, Enumerable.Range(0,11).Select( x => new SelectListItem { Text = x.ToString() }));

Html.DropDownListFor not behaving as expected ASP.net MVC

╄→尐↘猪︶ㄣ 提交于 2019-12-22 00:19:12
问题 I am new to ASP.net MVC and I am having trouble getting dropdown lists to work correctly. I have a strongly typed view that is attempting to use a Html.DropDownListFor as follows: <%=Html.DropDownListFor(Function(model) model.Arrdep, Model.ArrdepOptions)%> I am populating the list with a property in my model as follows: Public ReadOnly Property ArrdepOptions() As List(Of SelectListItem) Get Dim list As New List(Of SelectListItem) Dim arriveListItem As New SelectListItem() Dim departListItem

MVC5 view drop down list

空扰寡人 提交于 2019-12-21 03:18:09
问题 In a C# MVC5 Internet application view, how can I display a dropdown list for a user to select a list item that is populated from a View Model list? Here is the ViewModel code: public class MapLocationItemViewModel { [Editable(false)] public int mapLocationForeignKeyId { get; set; } public List<string> mapLocationItemTypes { get; set; } public MapLocationItem mapLocationItem { get; set; } } Here is the code that I currently have in the View : <div class="form-group"> @Html.LabelFor(model =>

Jquery ajax populate dropdown with json response data

让人想犯罪 __ 提交于 2019-12-20 04:06:52
问题 I know there are quite a few questions floating on this but I'm still not sure what to do. I have a HTML form called "CuisineForm", after the user selects the type of cuisine, the AJAX sends the form to the server. The AJAX call works fine, and server responds with a JSON responsewhich contains all the serving times of this particular cuisine. These serving times are divided into Breakfast, Lunch and Dinner. These times need to be populated into 3 separate dropdowns in the same form. but I

Select a default value in dropdownlistfor MVC 4

a 夏天 提交于 2019-12-19 05:32:24
问题 I'm trying to make a dropdownlistfor with a selected value but it doesn't work :/ And I search on the web but I don't find the solution :/ For the moment, I'm doing this : In C# : ViewBag.ID_VEH = new SelectList(db.VEHI, "ID_VEH", "COD_VEH", 4); // 4 is an example In my cshtml : @Html.DropDownListFor(model => model.ID_VEH, ViewBag.ID_VEH as SelectList) The dropdownlist is well complete but the default value is not selected :/ do you have an idea please ? 回答1: What I like to do is add a list

Strongly-typed binding to a DropDownListFor?

﹥>﹥吖頭↗ 提交于 2019-12-19 02:46:29
问题 Normally I would bind data to a DropDownListFor with a SelectList : @Html.DropDownListFor(model => model.CustomerId, new SelectList(Model.Orders, "OrderId", "ItemName")) Is there any way to do this through strongly-typed lambdas and not with property strings. For example: @Html.DropDownListFor(model => model.CustomerId, new SelectList(Model.Orders, x => x.OrderId, x => x.ItemName)) 回答1: You could create the select list itself in the controller and assign it to a property in your view model: