asp.net mvc - Html.EditFor not finding editor template -
please help! driving me insane.
i'm trying refactor code because there's bunch of cut-and-paste in models, views , controller.
view model
namespace foo.models.bar { [knowntype(typeof(recruiteditmodel))] public class recruiteditmodel { //... public commonserviceseditmodel services { get; set; }
services property contains class within model i'm putting mutual code.
view in foo\views
@model recruiteditmodel @* ... *@ @using (html.beginform("recruitedit", "appmgmt", formmethod.post, new { enctype = "multipart/form-data" })) { @* ... *@ @*@html.partial("tradeedit", model.services) <<< doesn't bind *@ @html.editorfor(m => m.services) @* binds *@ <input type="submit" value="save" /> }
using partial on nested class won't work because nested class won't bind. (http://lostechies.com/jimmybogard/2011/09/07/building-forms-for-deep-view-model-graphs-in-asp-net-mvc/)
so have utilize editor template.
editor template in foo\views\shared\editortemplates\tradeedit.cshtml
@model services.commonserviceseditmodel <div class="left"> <h3>howdy</h3> <div class="left thetrade">general contracting: </div> @html.editorfor(model => model.tradegc) @html.validationmessagefor(model => model.tradegc) </div> @*...*@
the problem i'm running apparently editor template isn't beingness found , instead default editor getting generated.
i found out while trying tweak css. "howdy" in header in editortemplate not beingness generated. no matter do, short of commenting out editfor phone call there's no alter displayed fields.
i'm running debugging on local iis , i've tried restarting app pool , refreshing website no joy.
how changes in editor template propagate view?
the reply in obvious not obvious. thought editor template resolve on model declaration in editor template. no, it's easier that.
the editor template must named {type}.cshtml.
another possibility have used uihint this:
[uihint("tradeedit")] public commonserviceseditmodel services { get; set; }
but haven't tested that.
thanks growing web answer.
asp.net-mvc razor
No comments:
Post a Comment