Please help! This is driving me insane.

I'm trying to refactor some code because there's a bunch of cut-and-paste in the Models, Views and Controller.

View Model

namespace Foo.Models.Bar
public class RecruitEditModel
    public CommonServicesEditModel Services { get; set; }

Services is a property that contains another class within the model where I'm putting the common 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 a partial on a nested class won't work because the nested class won't bind. (

So I have to use an editor template.

Editor Template in Foo\Views\Shared\EditorTemplates\TradeEdit.cshtml

@model Services.CommonServicesEditModel
    <div class="left">
        <div class="left theTrade">General Contracting:&nbsp;&nbsp;</div>
        @Html.EditorFor(model => model.TradeGC)
        @Html.ValidationMessageFor(model => model.TradeGC)

The problem I'm running into is that apparently the editor template isn't being found and instead a default editor is getting generated.

I found this out while trying to tweak the CSS. The "Howdy" in the header in the EditorTemplate is not being generated. No matter what I do, short of commenting out the EditFor call there's no change to the displayed fields.

I'm running debugging on local IIS and I've tried restarting the app pool and refreshing the website but no joy.

How do I get changes in the editor template to propagate to the view?

Related posts

Recent Viewed