Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7438561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:34:25+00:00 2026-05-29T10:34:25+00:00

I am a bit confused about how to implement EditorForModel. I get the idea

  • 0

I am a bit confused about how to implement EditorForModel. I get the idea of setting up templates in Views\Shared\EditorTemplates, but I think I have over-researched (if that’s possible) which has led to my confusion.

Basically, I am trying to minimize code replication. I have 5 services I provide to clients, and each service has between 4 – 6 different solutions. Making things more complex, there are certain types that can be shared among many of the solutions to varying degrees.

To make this simple, take the type:

public string FirstName { get; set; }

I will use this in every solution (and going up the “tree” in every service). But obviously I have numerous other types that will either be shared among a few solutions or none at all.

Let’s say I have 100 types for each service. I could separate them out as different View Models, but then I would have to factor that by the 5 services. I would prefer to just keep them all in one View Model, per service.

My trouble comes in when I try to create the templates. I want to use the templates because I am using a wizard and I don’t want to re-create a View for each part of the wizard in a particular solution especially if it’s the same “data” (and, again, factoring in the amount of solutions I have).

So, I create a BasicDetails.cshtml View (with types for things like FirstName, LastName and Email), which can actually be used across all the solutions. An editor template seems ideal here, but my confusion arises because if I use ServiceViewModelOne.cs and do an @Html.EditorForModel(), I would either spit out all 100 types or, using a template, only spit out that which I want in BasicDetails.cshtml by creating a template at \Views\Shared\EditorTemplates\ServiceViewModelOne.cshtml.

Now, would I be able to, for example, do the following:

@Html.EditorForModel("BasicDetails")
@Html.EditorForModel("WizardStep2")
@Html.EditorForModel("WizardStep3")

for every custom template I wanted to make (and however many more I wanted to make), all using the same ServiceViewModelOne.cs? If I am correct, I would then have the following folder structure:

  • \View\Shared\EditorTemplates\BasicDetails.cshtml
  • \View\Shared\EditorTemplates\WizardStep2.cshtml
  • \View\Shared\EditorTemplates\WizardStep3.cshtml
  • …

Obviously, within each template I would have the corresponding

<div class="editor-label">
    @Html.LabelFor(m => m.FirstName)
</div>
<div class="editor-field">
    @Html.EditorFor(m => m.FirstName)
    @Html.ValidationMessageFor(m => m.FirstName)
</div>
...

for all of the HTML inputs specific to that step in the wizard (which includes the entire HTML layout)

Would this be an appropriate way to do what I want, or am I barking up the wrong tree?

UPDATE:
I thought about using UIHint, but I am not sure if it will work completely.

I can use UIHint at the model level:

[UIHint("BasicDetails")]
public class MyModel {}

or at the type level

public class MyModel
    {
        [UIHint("FirstName")]
        public string FirstName { get; set; }
    }

And I could create a MyModel.cs and then auto map some of the types in there into MyViewModelOne.cs, MyViewModelTwo.cs, etc.

However, I think I will wind up boxing myself in, so to speak.

Let’s say I have Type1, Type2, Type3, Type4. Type1 can be used in every solution (keep it simple, lets say there are 4 solutions). Type2 and Type3 can be used in one solution, but not the others. And lets say that in another solution I can use Type2 and Type4.

Using UIHint or automapping means I’d have to create 3 different things to account for the above, and what if I need to use Type3 and Type4 in yet another solution.

I could be off base but it just seemed to restrictive forcing me to create multiple permutations, which is what I was hoping to avoid.

I will confess to not having used AutoMapper and am looking into whether or not that will help out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:34:26+00:00Added an answer on May 29, 2026 at 10:34 am

    UPDATE (ANSWER)
    I figured out how to handle this and in case this is useful to others am posting an answer. For my purposes this helps out tremendously and opens up lots of possibilities while adhering to DRY (somewhat) because it’s better to have one template than to have 6 files with the same fields.

    I posted this question because I tried putting a template at \Views\Shared\EditorTemplates\BasicDetails.cshtml and was just getting all my properties (fields such as FirstName) returned, rather than the few that I wanted (FirstName, LastName, EMail). Ordinarily placing the template in the \Shared\ folder would be the right thing to do IF I had a model BasicDetails.cs (for example).

    Reading the comments buried in Brad Wilson’s Post, I realized that I should instead try putting the template in

    \Views{CurrentController}\EditorTemplates\BasicDetails.cshtml.

    This works to show the view AND validation errors pop up on “Required” fields AND the wizard goes through its steps after clicking either “Next” or “Submit”

    To reiterate, I used

    @Html.EditorForModel("BasicDetails")
    

    where “BasicDetails” is the name of the template inside the Current Controller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i read Here and bit confused about the unregistering events. means i have button
I'm a bit confused about how to implement my state machine. I already know
I am a bit confused about socket programming in C. You create a socket,
I am bit confused about ADO.Net Data Services. Is it just meant for creating
I'm a bit confused about how many controllers I need, and when I can
I'm a bit confused about inheritance under sqlalchemy, to the point where I'm not
I'm a bit confused about the use of all the IEnumerable<T> extension methods, intellisense
I am a little bit confused about 2 things. Firstly when I create an
I'm a bit confused about how to overload the stream operators for my class
I am a bit confused about this. If you're building a distributed application, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.