formcollection

Getting all selected checkboxes from a FormCollection

痴心易碎 提交于 2019-11-30 20:39:19
I have a form which contains a whole bunch of checkboxes and some other types of control too. I need to retrieve the names of each selected checkbox. What is the best way to do this? Can I do it with a linq query maybe? So in pseudocode, I'm looking to do something like this: var names = formCollection .Where(c => c is Checkbox && c.Checked) .Select(c => c.Name); Update It seems the way MVC submits checkboxes is different from how a normal form would behave, as an hidden field is also rendered. I found the details here: How to handle checkboxes in ASP.NET MVC forms? Anywho, I've got it working

Getting all selected checkboxes from a FormCollection

假如想象 提交于 2019-11-30 05:11:31
问题 I have a form which contains a whole bunch of checkboxes and some other types of control too. I need to retrieve the names of each selected checkbox. What is the best way to do this? Can I do it with a linq query maybe? So in pseudocode, I'm looking to do something like this: var names = formCollection .Where(c => c is Checkbox && c.Checked) .Select(c => c.Name); Update It seems the way MVC submits checkboxes is different from how a normal form would behave, as an hidden field is also

formcollection only holds the selected html.listbox items values? MVC

这一生的挚爱 提交于 2019-11-30 05:01:54
My scenario is this: I have two listbox's, one that contains all my database items, and an empty one. The user adds the items needed from the full listbox to the empty listbox. I'm using a form to submit all the items the user has added. The problem is, only the selected items from the listbox are submitted. So if the user deselects some of the items, they wont be submitted in the form. My view looks like so: <% using (Html.BeginForm("MyAction", "MyController")) { %> <%= Html.ListBox("AddedItems", Model.Items)%> <input type="submit" value="Submit" name="SubmitButton"/> <% } %> My Controller

What is correct behaviour of UpdateModel in ASP.NET MVC?

你。 提交于 2019-11-29 23:10:11
I am interested to know what you guys feel should be deemed "correct behaviour" in terms of the UpdateModel method in ASP.NET MVC. The reason I ask here is perhaps if this functionality is "by design" somebody could clarify as to why it is the way it is, and perhaps a way to call it differently to achieve desired functionality, which I would imagine would be the way 90% of folk would want this to work? In essence, my gripe lies with the behaviour of the binding process within UpdateModel . Supposing you wish to update a form via a simple Save action method for which the data fields on the form

using two submit buttons inside single form

偶尔善良 提交于 2019-11-29 14:37:07
I have a form with two submit buttons in my asp.net mvc (C#) application. When i click any submit button in Google Chrome , by default the value of submit button is the first submit button's value. Here is the html: <input type="submit" value="Send" name="SendEmail" /> <input type="submit" value="Save As Draft" name="SendEmail" /> <input type="button" value="Cancel" /> When i click the Save As Draft button, in the action of the controller, it gets "Send" as the value for SendEmail . Here is the action: public ActionResult SendEmail(string SendEmail, FormCollection form) { if(SendEmail == "Send

MVC Razor get option value from select with FormCollection

若如初见. 提交于 2019-11-29 12:55:58
问题 My view has a Select with elements(options) from my ViewModel. @using (Html.BeginForm("NewUser", "Admin")) { <select multiple="" id="inputRole" class="form-control" size="6" name="inputRole"> @foreach (var item in Model.roller) { <option>@item.Name</option> } </select> } How can i get the selected value in my Controller? [HttpPost] public ActionResult NewUser(FormCollection formCollection) { String roleValue1 = formCollection.Get("inputRole"); } This gives me a null value. 回答1: Try this to

formcollection only holds the selected html.listbox items values? MVC

冷暖自知 提交于 2019-11-29 02:38:53
问题 My scenario is this: I have two listbox's, one that contains all my database items, and an empty one. The user adds the items needed from the full listbox to the empty listbox. I'm using a form to submit all the items the user has added. The problem is, only the selected items from the listbox are submitted. So if the user deselects some of the items, they wont be submitted in the form. My view looks like so: <% using (Html.BeginForm("MyAction", "MyController")) { %> <%= Html.ListBox(

using two submit buttons inside single form

戏子无情 提交于 2019-11-28 08:29:00
问题 I have a form with two submit buttons in my asp.net mvc (C#) application. When i click any submit button in Google Chrome , by default the value of submit button is the first submit button's value. Here is the html: <input type="submit" value="Send" name="SendEmail" /> <input type="submit" value="Save As Draft" name="SendEmail" /> <input type="button" value="Cancel" /> When i click the Save As Draft button, in the action of the controller, it gets "Send" as the value for SendEmail . Here is