Search Results

Search found 121 results on 5 pages for 'formcollection'.

Page 1/5 | 1 2 3 4 5  | Next Page >

  • How to build C# object from a FormCollection with complex keys

    - by ob
    i have a javascript object, obj, that gets passed to an mvc action via a $.post() like so: var obj = { Items: [{ Text: "", Value: { Property1: "", Property2: "" }, { Text: "", Value: { Property1: "", Property2: "" }] }; $.post('MyAction', obj, function() {}); the action signature looks like this: public ActionResult MyAction(FormCollection collection) { } i need to be able to build an object from the FormCollection, however i'm running into an issue where the keys are in the form: "Items[0][Text]" "Items[0][Value][Property1]" "Items[0][Value][Property2]" "Items[1][Text]" "Items[1][Value][Property1]" "Items[1][Value][Property2]" i'm wondering if there's a clean way to build the desired C# object from the given FormCollection. i understand that i could change the action method signature to take in the type of object i'm interested in, but that was presenting its own issues.

    Read the article

  • Converting formCollection array to objects in the controller

    - by bergin
    in my view I have several [n].propertyName array fields I want to turn the formCollection fields into objects myobject[n].propertyName when it goes to the controller. so for example, the context: View: foreach (var item in Model.SSSubjobs.AsEnumerable()) <%: Html.Hidden("["+c+"].sssj_id", item.sssj_id ) %> <%: Html.Hidden("["+c+"].order_id", item.order_id ) %> <%: Html.TextBox("["+c+"].farm", item.farm %> <%: Html.TextBox("["+c+"].field", item.field %> c++; Controller: I want to take the above [0].sssj_id and turn into sssj[0].sssj_id or a list of sssj objects My first idea was to look in the form collection for things starting with "[" but I have a feeling this isnt right... this is as far as I got: public IList<SoilSamplingSubJob> extractSSSJ(FormCollection c) { IList<SoilSamplingSubJob> sssj_list=null; SoilSamplingSubJob sssj; var n=0; foreach (var key in c.AllKeys) // iterate through the formcollection { var value = c[key]; if(key.StartsWith("[")) // ie turn [0].gps_pk_chx into sssj.gps_pk_chx ??? } return sssj_list; }

    Read the article

  • Getting multiple checkboxes from FormCollection element

    - by FreshCode
    Given multiple HTML checkboxes: <input type="checkbox" name="catIDs" value="1" /> <input type="checkbox" name="catIDs" value="2" /> ... <input type="checkbox" name="catIDs" value="100" /> How do I retrive an array of integers from a FormCollection in an action: public ActionResult Edit(FormCollection form) { int [] catIDs = (IEnumerable<int>)form["catIDs"]; // ??? // alternatively: foreach (int catID in form["catIDs"] as *SOME CAST*) { // ... } return View(); } Note: I read the related questions and I don't want to change my action parameters, eg. Edit(int [] catIDs).

    Read the article

  • MVC : Checkboxes generated using JavaScript not appearing in FormCollection on postback

    - by Andy Evans
    I took over another project (written by one contractor, modified by another and now it's not working) written using MVC/C# where a view that has a table (see below) is dynamically populated using JSON/Javascript - the first column of which is a checkbox. View (spark view engine) <table id='component_list' name='component_list' cellpadding='0' border='0' cellspacing='0'> <thead> <tr> <th>&nbsp;</th> <th>Component</th> <th>Component Type</th> <th>Evenflo Part #</th> <th>Supplier Part #</th> <th>Supplier</th> <th>Requirement</th> <th>Location</th> <th>Region</th> </tr> </thead> <tbody> </tbody> </table> When the page is rendered, I look at the source for the page and do not see the table data (I wouldn't expect to see this). However, when the form is posted back, controller, the FormCollection is empty. Supposedly this had been working before the last contractor got their hands on it - which is another post all together. My goal right now is having the checkboxes in the FormCollection. Any suggestions would be greatly appreciated. Thanks,

    Read the article

  • Dynamically inserted input elements not showing up in ActionResult's FormCollection parameter

    - by roosteronacid
    I am adding input elements to a view, dynamically, using JavaScript. But I am unable to find those inputs in my ActionResult's FormCollection parameter...: public ActionResult Del(FormCollection fc) I am able to find static input elements in the View. And using FireBug in Mozilla FireFox, I can see that the inputs are inside of the form element, in the DOM, and are not floating around somewhere random. How can I access these inputs?

    Read the article

  • Get the selected drop down list value from a FormCollection in MVC

    - by James Santiago
    I have a form posting to an action with MVC. I want to pull the selected drop down list item from the FormCollection in the action. How do I do it? My Html form: <% using (Html.BeginForm()) {%> <select name="Content List"> <% foreach (String name in (ViewData["names"] as IQueryable<String>)) { %> <option value="<%= name %>"><%= name%></option> <% } %> </select> <p><input type="submit" value="Save" /></p> <% } %> My Action: [HttpPost] public ActionResult Index(FormCollection collection) { //how do I get the selected drop down list value? String name = collection.AllKeys.Single(); return RedirectToAction("Details", name); }

    Read the article

  • asp.net mvc formcollection

    - by mazhar
    public ActionResult Edit(int id, FormCollection formValues) { 07. 08. // Retrieve existing dinner 09. Dinner dinner = dinnerRepository.GetDinner(id); 10. 11. // Update dinner with form posted values 12. dinner.Title = Request.Form["Title"]; 13. dinner.Description = Request.Form["Description"]; 14. dinner.EventDate = DateTime.Parse(Request.Form["EventDate"]); 15. dinner.Address = Request.Form["Address"]; 16. dinner.Country = Request.Form["Country"]; 17. dinner.ContactPhone = Request.Form["ContactPhone"]; 18. 19. // Persist changes back to database 20. dinnerRepository.Save(); 21. 22. // Perform HTTP redirect to details page for the saved Dinner 23. return RedirectToAction("Details", new { id = dinner.DinnerID }); 24.} formValues is not used in any form, what is the used of it.

    Read the article

  • MVC 1.0 FormCollection wiped out by running SSRS report

    - by Dale
    I have an MVC 1.0 app with a form that works just fine. The app also launches an SSRS using the URL ReportServer interface (**Not the Webform ReportViewer Control!). This also works just fine. But if I export the generated SSRS report (say to .pdf), and then return to the MVC application, no form will work. By "not work" I mean that on the Post action, the form collection is not returned. I'm completely lost as to what could be causing this behavior. Any ideas? Thanks in advance.

    Read the article

  • FormCollection in VB.NET

    - by fireBand
    Hi, I want to detect if a window form is open and if it is then I would like to bring it in front rather than opening it again. I know I need a form collection for this but I want to know if there is a built in form collection that holds all the forms in VB.NET or I need to implement my own. Thank you.

    Read the article

  • formcollection not see me all inputs

    - by sanfra1983
    Hi, I have a View where some input text to be added dynamica using jquery, I mean everything funzona, and when I go to add these inputs and do right button on the browser I'm not seeing the added input. function addPerson () ( current + +; StrToAdd var = '<table id="compo" name="compo"' + current +'> <tr> <td> <label for="firstname"' + current +'"> Name </ label> <input id = 'firstname' + current + '"name =" Componenti.Nome_ "' +" "+ current +" "+ '" size = "29" /> </ td> <td> <label for = "lastname"' current + + '"> Name </ label> <input id="lastname''" name="Componenti.Cognome_"' + + + current + current'" size="29" /> </ td>' StrToAdd + = '<td> <label for="luogonascita"' + current +'"> LuogoNascita </ label> <input id = "luogodinascita' + current + '" name = "Componenti.Luogonascita_"' + "" + current + "" + '"size =" 29 "/> </ td>' StrToAdd + = '<td> <label for="datanascita"' + current +'"> DataNacita </ label> <input id = "dateOfBirth' + current + '" name = "Componenti.datanascita_"' + current + ' "size =" 29 "/> </ td> </ tr> </ table> ' StrToAdd + = '<script type="text/javascript"> jQuery (function ($) {$("# dateOfBirth' + current + '). mask ("' + mask +'")});</ script > '; $ ('# Components'). Append (StrToAdd); ) The problem is that when I pass the data via post in the action, and I go to create the education var valueProvider= formanagrafica.ToValueProvider(); valueProvider I find all the input I have added only one and that therefore there are more than one gives me the values separated by commas. How can I retrieve the values of a line of input text? I hope I explained correctly.

    Read the article

  • what is wrong with this insert method in asp.net mvc?

    - by Pandiya Chendur
    My controller calls a repository class method on insert, [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create([Bind(Exclude = "Id")]FormCollection collection) { try { MaterialsObj materialsObj = new MaterialsObj(); materialsObj.Mat_Name = collection["Mat_Name"]; materialsObj.Mes_Id = Convert.ToInt64(collection["MeasurementType"]); materialsObj.Mes_Name = collection["Mat_Type"]; materialsObj.CreatedDate = System.DateTime.Now; materialsObj.CreatedBy = Convert.ToInt64(1); materialsObj.IsDeleted = Convert.ToInt64(1); consRepository.createMaterials(materialsObj); return RedirectToAction("Index"); } catch { return View(); } } and my repository class has this, public MaterialsObj createMaterials(MaterialsObj materialsObj) { db.Materials.InsertOnSubmit(materialsObj); return materialsObj; } But when i compile this i get The best overloaded method match for 'System.Data.Linq.Table<CrMVC.Models.Material>.InsertOnSubmit(CrMVC.Models.Material)' has some invalid arguments... cannot convert from 'CrMVC.BusinessObjects.MaterialsObj' to 'CrMVC.Models.Material'.. am i missing something?

    Read the article

  • ASP.NET MVC2 - specific fields in form pass via a specific object?

    - by ile
    In database I have Contacts table: ContactID (int) FirstName (varchar) LastName (varchar) ... XmlFields (xml) // This field is xml type To create a new contact, I created two classes - one for regular fields and other to display fields from XmlFields field. In Controller, I have following: public ActionResult Create(Contact contact, FormCollection collection) ... Regular field I catch with contact object and those that need to be stored as xml in XmlFields I try to catch with collection object. Problem is that collection object catches all fields, so I wonder if it is possible to isolate xml fields when posting to a specific object so that I can easily manipulate with them. I need this in separated objects because these xml fields are going to be generated dynamically and will be different for every user. Thanks in advance, Ile

    Read the article

  • Getting values from the html to the controller

    - by tina
    Hi, I'm trying to access the values a user introduces in a table from my controller. This table is NOT part of the model, and the view source code is something like: <table id="tableSeriales" summary="Seriales" class="servicesT" cellspacing="0" style="width: 100%"> <tr> <td class="servHd">Seriales</td> </tr> <tr id="t0"> <td class="servBodL"> <input id="0" type="text" value="1234" onkeypress = "return handleKeyPress(event, this.id);"/> <input id="1" type="text" value="578" onkeypress = "return handleKeyPress(event, this.id);"/> . . . </td> </tr> </table> How can I get those values (1234, 578) from the controller? Receiving a formcollection doesn't work since it does not get the table... Thank you.

    Read the article

  • List box values on postback

    - by kapil
    Hi, I am using asp.net mvc. I have used two list box in one of my views. I transfer desired items from left-hand-side list box to right-side list box. On a button click, i want to get the list box contents from right side list box. I don;t get in form collection. Can anyone please suggest how can I get it? thanks, kapil

    Read the article

  • How to optimize this javascript code?

    - by Andrija
    I have a jsp which uses a lot of javascript and it's just not fast enough. I would like to optimize it so first, here's a part of the code: In the jsp I have the initialization: window.onload = function () { formCollection.pageSize.value = "<%= pagingSize%>"; elemCollection = iDom3.Table.all["spis"].XML.DOM; <% if (resultList != null) { %> elementsNumber = <%= resultList.size() %>; <%} else { %> elementsNumber = 0; <% } %> contextPath = "<%= request.getContextPath() %>"; } In my js file I have two types of js functions: // gets the first element and sets it's value to all the other; //the selectSingleNode function is used because I use XSLT transformation //to generate the table _setTehJed = function(){ var resultId = formCollection.elements["idTehJedinice_spis_1"].value; var resultText = formCollection.elements["tehnicka_spis_1"].value; if (resultId != ""){ var counter = 1; while (counter<elementsNumber){ counter++; if(formCollection.elements["idTehJedinice_spis_"+counter] != null){ formCollection.elements["idTehJedinice_spis_"+counter].value=resultId; formCollection.elements["tehnicka_spis_"+counter].value=resultText; } var node=elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+counter+"']/data[@col = 'tehnicka']/title"); node.text=resultText; var node2=elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+counter+"']/data[@col = 'idTehJedinice']/title"); node2.text=resultId; } } } // sets the elements checkbox to checked or unchecked _SelectCheckRokCuvanja = { all : [], Item : function (oItem, sId) { this.all["spis_"+sId] = oItem.value; if (oItem.checked) { elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+sId+"']/data[@col = 'rokCheck']").setAttribute("default", "true"); }else{ elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+sId+"']/data[@col = 'rokCheck']").setAttribute("default", "false"); } } } I've used these tips: http://blogs.msdn.com/b/ie/archive/2006/08/28/728654.aspx http://code.google.com/speed/articles/optimizing-javascript.html but I still think something could be done like defining the functions like this: In the jsp: window.onload = function () { iDom3.DigitalnaArhivaPrihvat.formCollection=document.forms["controller"]; iDom3.DigitalnaArhivaPrihvat.formCollection.pageSize.value = "<%= pagingSize%>"; iDom3.DigitalnaArhivaPrihvat.elemCollection = iDom3.Table.all["spis"].XML.DOM; <% if (resultList != null) { %> iDom3.DigitalnaArhivaPrihvat.elementsNumber = <%= resultList.size() %> <%} else { %> iDom3.DigitalnaArhivaPrihvat.elementsNumber = 0; <% } %> } in the js: iDom3.DigitalnaArhivaPrihvat = { formCollection:null, elemCollection:null, elementsNumber:null, _setTehJed : function(){ var resultId = this.formCollection.elements.idTehJedinice_spis_1.value; var resultText = this.formCollection.elements.tehnicka_spis_1.value; if (resultId != ""){ var counter = 1; while (counter<this.elementsNumber){ counter++; if(this.formCollection.elements["idTehJedinice_spis_"+counter] !== null){ this.formCollection.elements["idTehJedinice_spis_"+counter].value=resultId; this.formCollection.elements["tehnicka_spis_"+counter].value=resultText; } var node=this.elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+counter+"']/data[@col = 'tehnicka']/title"); node.text=resultText; var node2=this.elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+counter+"']/data[@col = 'idTehJedinice']/title"); node2.text=resultId; } } }, _SelectCheckRokCuvanja = { all : [], Item : function (oItem, sId) { this.all["spis_"+sId] = oItem.value; if (oItem.checked) { this.elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+sId+"']/data[@col = 'rokCheck']").setAttribute("default", "true"); }else{ this.elemCollection.selectSingleNode("/suite/table/rows/row[@id = 'spis_"+sId+"']/data[@col = 'rokCheck']").setAttribute("default", "false"); } } } but the problem is scoping (if I do it like this, the second function does not execute properly). Any suggestions?

    Read the article

  • How to loop through the FormCollection to check if textboxes have values?

    - by Sasha
    Hi there. I have a search page that has 6 textboxes which i pass as FormCollection to the action in the controller. I dont want to search for records if ther is no values in textboxes. Is there a way to loop through all textboxes in FormCollection without to check which ones have values in them? I am a student in the college and this project is part of my summer experience program. I realize that this is a newbie question :) Thank you!

    Read the article

  • how to get value of button through jquery in formcollection with id of form collection?

    - by AbhijitPandya
    i have formcollection and two buttons like <form id="frmSubmitTax" method="post"> <input type="submit" id="btnTaxSave" value="Save" /> <input type="submit" id="btnTaxNext" value="Next" /> </form> i m submitting form through jquery and i want to get value of button while form submitting jquery code $('frmSubmitTax').live('submit', function (e) { get value of button that which button is submitted...... });

    Read the article

  • Odd "Object reference not set to an instance of an object" involving xWinForms

    - by Kyle
    Hey, I've been trying to get the xWinForms 3.0 library (a library with forms support in xna) working with my C# XNA Game project but I keep getting the same problem. I add the reference to my project, put in the using statement, declare a formCollection variable and then I try to initialize it. whenever I run the project I get stopped on this line: formCollection = new FormCollection(this.Window, Services, ref graphics); it gives me the error: " System.NullReferenceException was unhandled Message="Object reference not set to an instance of an object." Source="Microsoft.Xna.Framework" StackTrace: at Microsoft.Xna.Framework.Graphics.VertexShader..ctor(GraphicsDevice graphicsDevice, Byte[] shaderCode) at Microsoft.Xna.Framework.Graphics.SpriteBatch.ConstructPlatformData() at Microsoft.Xna.Framework.Graphics.SpriteBatch..ctor(GraphicsDevice graphicsDevice) at xWinFormsLib.FormCollection..ctor(GameWindow window, IServiceProvider services, GraphicsDeviceManager& graphics) at GameSolution.Game2.LoadContent() in C:\Users\Owner\Documents\School\Year 3\Winter\Soen 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Game2.cs:line 45 at Microsoft.Xna.Framework.Game.Initialize() at GameSolution.Game2.Initialize() in C:\Users\Owner\Documents\School\Year 3\Winter\Soen 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Game2.cs:line 37 at Microsoft.Xna.Framework.Game.Run() at GameSolution.Program.Main(String[] args) in C:\Users\Owner\Documents\School\Year 3\Winter\Soen 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Program.cs:line 14 InnerException: " In a project I downloaded that used the xWinForms, I put the following code in and it compiled and ran no error. but when I put it in my project I get the error. Am I making some stupid mistake about including dlls or something? I've been at this for hours and I can't seem to find anything that would cause this. using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage; using xWinFormsLib; namespace GameSolution { public class Game2 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; FormCollection formCollection; public Game2() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); } protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); formCollection = new FormCollection(this.Window, Services, ref graphics); } protected override void Update(GameTime gameTime) { base.Update(gameTime); } protected override void Draw(GameTime gameTime) { base.Draw(gameTime); } } } Any help would be greatly appreciated ._.

    Read the article

  • What&rsquo;s Wrong With This Code (#25)

    The goal: create an extension method that will make it easy to create FormCollection objects. The method is a helper for unit testing ASP.NET MVC code. public static FormCollection ToFormCollection(this object data) { var namesAndValues = data.GetType() .GetProperties() .WhereValueIsNotDefaultValue(data) .ToNameValueCollection(data); return new FormCollection(namesAndValues); } The extension method itself relies on a couple private extension...Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • ASP.NET MVC - Form Post always redirect when I just want to bind json result to a div

    - by Saxman
    Hi all, I'm having a little problem with json result. I'm submitting a contact form, and after the submission, I just want to return some json data (indicating either a success or failed and displays a message) back to the view, without causing a redirect, but it kept redirecting me to the action, here are the codes: HTML <div id="contactForm2" class="grid_6"> <div id="contactFormContainer"> @using (Html.BeginForm(MVC.Home.ActionNames.ContactForm, MVC.Home.Name, FormMethod.Post, new { id = "contactForm" })) { <p> <input type="text" tabindex="1" size="22" value="" id="contactName" class="text_input required" name="contactName" /> <label for="contactName"> <strong class="leftSpace">Your Name (required)</strong></label></p> <p> <input type="text" tabindex="2" size="22" value="" id="contactEmail" class="text_input required" name="contactEmail" /> <label for="contactEmail"> <strong class="leftSpace">Email (required)</strong></label></p> <p> <input type="text" tabindex="2" size="22" value="" id="contactPhone" class="text_input" name="contactPhone" /> <label for="contactPhone"> <strong class="leftSpace">Phone</strong></label></p> <p> <label> <strong class="leftSpace n">Message (required)</strong></label> <textarea tabindex="4" rows="4" cols="56" id="contactMessage" class="text_area required" name="contactMessage"></textarea></p> <p> <input type="submit" value="Send" tabindex="5" id="contactSubmit" class="button submit" name="contactSubmit" /></p> } </div> <div id="contactFormStatus"> </div> </div> Controller [HttpPost] public virtual JsonResult ContactForm(FormCollection formCollection) { var name = formCollection["contactName"]; var email = formCollection["contactEmail"]; var phone = formCollection["contactPhone"]; var message = formCollection["contactMessage"]; if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(message)) { return Json(new { success = false, message = "Please complete all the required fields so that I can get back to you. Thanks." }); } // Insert contact form data here... return Json(new { success = true, message = "Your inquery has been sent. Thank you." }); } javascript $(document).ready(function () { $('#contactSubmit').live('click', function () { var form = $('#contactForm'); var formData = form.serialize(); $.post('/Home/ContactForm', formData, function (result) { var status = $('#contactFormStatus'); if (result.success) { $('#contactForm')[0].reset; } status.append(result.message); }, 'json' ); return false; }); }); I've also tried this javascript, but also got a redirect $(document).ready(function () { $('#contactSubmit').live('click', function () { var form = $('#contactForm'); var formData = form.serialize(); $.ajax({ type: 'POST', url: '/Home/ContactForm', data: formData, success: function (result) { SubmitContactResult(result); }, cache: false }); }); function SubmitContactResult(result) { var status = $('#contactFormStatus'); if (result.success) { $('#contactForm')[0].reset; } status.append(result.message); } }); Any idea what's going on with my code? Thank you very much.

    Read the article

  • What is the way to go to fake my database layer in a unit test?

    - by Michel
    Hi, i have a question about unit testing. say i have a controller with one create method which puts a new customer in the database: //code a bit shortened public actionresult Create(Formcollection formcollection){ client c = nwe client(); c.Name = formcollection["name"]; ClientService.Save(c); { Clientservice would call a datalayer object and save it in the database. What i do now is create a database testscript and set my database in a know condition before testing. So when i test this method in the unit test, i know that there must be one more client in the database, and what it's name is. In short: ClientController cc = new ClientController(); cc.Create(new FormCollection (){name="John"}); //i know i had 10 clients before assert.areEqual(11, ClientService.GetNumberOfClients()); //the last inserted one is John assert.areEqual("John", ClientService.GetAllClients()[10].Name); So i've read that unit testing should not be hitting the database, i've setup an IOC for the database classes, but then what? I can create a fake database class, and make it do nothing. But then ofcourse my assertions will not work because if i say GetNumberOfClients() it will alwasy return X because it has no interaction with the fake database class used in the Create Method. I can also create a List of Clients in the fake database class, but as there will be two different instance created (one in the controller action and one in the unit test), they will have no interaction. What is the way to make this unit test work without a database?

    Read the article

  • Html.EditorFor not updating model on post

    - by Dave
    I have a complex type composed of two nullable DateTimes: public class Period { public DateTime? Start { get; set; } public DateTime? End { get; set; } public static implicit operator string(Period period) { /* converts from Period to string */ } public static implicit operator Period(string value) { /* and back again */ } } I want to display them together in a single textbox as a date range so I can provide a nice jQuery UI date range selector. To make that happen have the following custom editor template: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Period>" %> <% string name = ViewData.TemplateInfo.HtmlFieldPrefix; %> <%= Html.PeriodTextBox(name, Model.EarliestDate, Model.LatestDate) %> Where Html.PeriodTextBox is an extension method I've written that just concatenates the two dates sensibly, turns off autocomplete and generates a textbox, like so: public static MvcHelperString PeriodTextBox(this HtmlHelper helper, string name, DateTime? startDate, DateTime? endDate) { TagBuilder builder = new TagBuilder("input"); builder.GenerateId(name); builder.Attributes.Add("name", name); builder.Attributes.Add("type", "text"); builder.Attributes.Add("autocomplete", "off"); builder.Attributes.Add("value", ConcatDates(startDate, endDate)); return MvcHtmlString.Create(builder.ToString()); } That's working fine in that I can call <%= Html.EditorFor(m => m.ReportPeriod) %> and I get my textbox, then when the form is submitted the FormCollection passed to the post action will contain an entry named ReportPeriod with the correct value. [HttpPost] public ActionResult ReportByRange(FormCollection formValues) { Period reportPeriod = formValues["ReportPeriod"]; // creates a Period, with the expected values } The problem is if I replace the FormCollection with the model type I'm passing to the view then the ReportPeriod property never gets set. [HttpPost] public ActionResult ReportByRange(ReportViewModel viewModel) { Period reportPeriod = viewModel.ReportPeriod; // this is null } I expected MVC would try to set the string from the textbox to that property and it would automatically generate a Period (as in my FormCollection example), but it's not. How do I tell the textbox I've generated in the custom editor to poplate that property on the model?

    Read the article

1 2 3 4 5  | Next Page >