The problem here is the way html helpers work (all of them): when trying to bind they will first look in the POST request values and after that the model and viewdata to pull values. This is by design. It basically means that even if in your post controller action you try to modify the values the html helper won't use them and pick those that were initially posted by the user %= Html.
DropDownListFor(m => m. DropFontFamily, ViewData"FontFamilyList" as List, new { Class = "UpdatesDropDownExample" }) % The DropDownListFor helper detects that there is a posted value for ResultFontFamily and will use it instead of the one you supply in your controller A possible workaround is to write your own helper.
The problem here is the way html helpers work (all of them): when trying to bind they will first look in the POST request values and after that the model and viewdata to pull values. This is by design. It basically means that even if in your post controller action you try to modify the values the html helper won't use them and pick those that were initially posted by the user.M.
DropFontFamily, ViewData"FontFamilyList" as List, new { Class = "UpdatesDropDownExample" }) %> The DropDownListFor helper detects that there is a posted value for ResultFontFamily and will use it instead of the one you supply in your controller. A possible workaround is to write your own helper.
I must not have stated the problem clearly. The html helpers are doing exactly what they should and expected. They display what I pass to them in the model.
The question was about the binders. When the property of the model is a class passed to a partial view, it isn't populated by the binder. I have to include an additional parameter in the post controller action to get the binder to populate it with the user input.
– user313118 Apr 12 '10 at 14:48.
If you look at the debugger and set a breakpoint on public SiteProperties() { ***HERE*** DropFontFamily = "Arial, Helvetica, Sans-serif"; } then you can see that when you do the postback it for some reason is trying to the default constructor before it gets to PopulateProperyDropDownLists(); ubiquitous-tech.blogspot.com/2009/05/asp... has several options on how to handle the post back part also public class ResultPageProperties { public ResultPageProperties() { ResultFontFamily = "Arial, Helvetica, Sans-serif"; } private string _resultFontFam; public string ResultFontFamily { get { return _resultFontFam; } set { _resultFontFam = value; } } } seems to work ... I couldnt begin to tell you why though.
Thanks for the help Hurricanepkt. I think the two ways of declaring the ResultFontFamily property are equivalent. That did get me thinking about the way I was initializing the class property though.
Since I'm checking for null in my getter, I'm always getting the original values. When I take that out I am left with a null value on the post controller method. – user313118 Apr 9 '10 at 21:30.
If I change the way I declare my ResultPageProperties property to public ResultPageProperties ResultPagePropertyList { get; set; } in place of private ResultPageProperties m_ResultPagePropertyList; public ResultPageProperties ResultPagePropertyList { get { if (m_ResultPagePropertyList == null) m_ResultPagePropertyList = new ResultPageProperties(); return m_ResultPagePropertyList; } set { m_ResultPagePropertyList = value; } } It is null on the post method. So the binder appears to ignore it. So I changed the controller method to the following which did work.
AcceptVerbs(HttpVerbs. Post) public ActionResult SiteOptions(SiteProperties properties, ResultPageProperties resultPageProp) { properties. ResultPagePropertyList = resultPageProp; PopulateProperyDropDownLists(); return View("SiteOptions", properties); }.
Use Html. EditorFor instead of Html.RenderPartial. See Model binding with nested child models and PartialViews in ASP.NET MVC.
I have a class that contains another class as one of its properties. My controller just grabs the SiteProperties and returns the view. On submit, it accepts SiteProperties and returns the same view.
The view contains a partial view that renders the ResultPageProperties Model. OK, so when the page renders, you get "Arial, ..." in both selects. If you choose another option for both and click submit, the binder populates the SiteProperties object and passes it to the controller.
However, the ResultFontFamily always contains the original value. I was expecting it to have the value the user selected. What am I missing?
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.