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

  • SEARCH
  • Home
  • 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 1028529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:24:08+00:00 2026-05-16T12:24:08+00:00

I’ve got a model which contains a List of QuestionEditModel for which I want

  • 0

I’ve got a model which contains a List of QuestionEditModel for which I want to use an EditorFor.

Normally, I would just call EditorFor on the collection and MVC will do the rest. However, I need the individual QuestionEditModel to use different EditorTemplates depending on the value of a field within the object.

I would’ve thought that the method for doing this would be something like

<%: Html.EditorFor(model=>model.Questions), [fieldname from individual question] %>

but I cannot figure out how to tell it to look at the Question which is currently selected and use the EntryType field from the question to determine which EditorTemplate to use.

So I tried this

            <% foreach (Reviewer.Models.QuestionEditModel qem in Model.Questions)
           {
               Html.EditorFor(q=>qem, qem.EntryType, null);
           } %>

but this doesn’t render anything on to the page. The odd thing is that if I set a breakpoint and run over the code, this does call the correct EditorTemplate, the correct model data is passed in and there are no exceptions, but it just doesn’t render anything.

Is there some additional work I need to do in this scenario to get the rendered EditorTemplate back in to my page?

EDIT:

Full code of the Edit View.

<% using (Html.BeginForm()) {%>
    <%: Html.ValidationSummary(true) %>

    <%: Html.HiddenFor(model=>model.AcadPeriod) %>
    <%: Html.HiddenFor(model=>model.ReviewID) %>
    <%: Html.HiddenFor(model=>model.ReviewName) %>
    <%: Html.HiddenFor(model=>model.CategoryID) %>
    <%: Html.HiddenFor(model=>model.CategoryName) %>
    <%-- Categories not getting returned in model for some reason. Use EditorFor or DisplayFor instead of loop? --%>
    <%: Html.HiddenFor(model=>model.Categories) %>
    <%: Html.HiddenFor(model=>model.ClassificationID) %>
    <%: Html.HiddenFor(model=>model.ClassificationName) %>

    <div style="width:100%">

    <div style="float:left">
        <ul style="list-style-type:none">
            <% for (int i = 0; i < Model.Categories.Count(); i++)
               { %>
            <li style="background-color:Gray; border: 1px solid black; padding: 3px 3px 3px 3px; margin-bottom: 2px">
            <%: Html.ActionLink(Model.Categories[i].name, "Edit", new { AcadPeriod = Model.AcadPeriod, ClassificationID=Model.ClassificationID, ReviewID=Model.ReviewID, CategoryID=Model.Categories[i].category_id })%>
            </li>
            <% }%>
        </ul>
    </div>

    </div>
                <% foreach (Reviewer.Models.QuestionEditModel qem in Model.Questions) { %> 
                     <%: Html.EditorFor(q=>qem, qem.EntryType,null); %> 
                <% } %> 

        <p>
            <input type="submit" value="Save" />
        </p>

<% } %>

EDIT 2:

Complete View, Controller, and Template code as requested.

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Reviewer.Models.ReviewEditModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Edit
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<h1><%: Model.AcadPeriod %> &gt; <%: Model.ClassificationName %> &gt; <%: Model.ReviewName %></h1>

<% using (Html.BeginForm()) {%>
    <%: Html.ValidationSummary(true) %>

    <%: Html.HiddenFor(model=>model.AcadPeriod) %>
    <%: Html.HiddenFor(model=>model.ReviewID) %>
    <%: Html.HiddenFor(model=>model.ReviewName) %>
    <%: Html.HiddenFor(model=>model.CategoryID) %>
    <%: Html.HiddenFor(model=>model.CategoryName) %>
    <%-- Categories not getting returned in model for some reason. Use EditorFor or DisplayFor instead of loop? --%>
    <%: Html.HiddenFor(model=>model.Categories) %>
    <%: Html.HiddenFor(model=>model.Questions) %>
    <%: Html.HiddenFor(model=>model.ClassificationID) %>
    <%: Html.HiddenFor(model=>model.ClassificationName) %>

    <div style="width:100%">

    <div style="float:left;width: 15%">
        <ul style="list-style-type:none">
            <% for (int i = 0; i < Model.Categories.Count(); i++)
               { %>
            <li style="background-color:Gray; border: 1px solid black; padding: 3px 3px 3px 3px; margin-bottom: 2px">
            <%: Html.ActionLink(Model.Categories[i].name, "Edit", new { AcadPeriod = Model.AcadPeriod, ClassificationID=Model.ClassificationID, ReviewID=Model.ReviewID, CategoryID=Model.Categories[i].category_id })%>
            </li>
            <% }%>
        </ul>
    </div>

    <div style="float:left; width: 80%; margin-left: 5px">

<% foreach (Reviewer.Models.QuestionEditModel qem in Model.Questions) { %> 
 <%: Html.EditorFor(q=>qem, qem.EntryType,null) %> 
<% } %> 

    </div>
    </div>
    <div style="clear:both" />
        <p>
            <input type="submit" value="Save" />
        </p>

<% } %>

<div>
    <%: Html.ActionLink("Back to List", "Index") %>
</div>

</asp:Content>

Editor Template:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Reviewer.Models.QuestionEditModel>" %>

<div style="width:100%; border: 1px solid black">
 <div style="width: 100%; border: 1px solid black"><h2><%: Model.QuestionName %></h2></div>
<div style="width:25%; display:inline; border: 1px solid black; float:left">
    <%: Model.QuestionText %>
</div>
<div style="width:70%; border: 1px solid black; float:left">
    <%: Html.TextAreaFor(model=>model.Answer) %>
    <%:Html.ValidationMessageFor(model=>model.Answer) %>
</div>

 <div style="clear:both" />
</div>

    <fieldset>
        <legend>TEXT</legend>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.QuestionID) %>
        </div>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.QuestionID) %>
            <%: Html.ValidationMessageFor(model => model.QuestionID) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.QuestionName) %>
        </div>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.QuestionName) %>
            <%: Html.ValidationMessageFor(model => model.QuestionName) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.QuestionText) %>
        </div>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.QuestionText) %>
            <%: Html.ValidationMessageFor(model => model.QuestionText) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.DefaultText) %>
        </div>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.DefaultText) %>
            <%: Html.ValidationMessageFor(model => model.DefaultText) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.EntryType) %>
        </div>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.EntryType) %>
            <%: Html.ValidationMessageFor(model => model.EntryType) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.HelpText) %>
        </div>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.HelpText) %>
            <%: Html.ValidationMessageFor(model => model.HelpText) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.Answer) %>
        </div>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.Answer) %>
            <%: Html.ValidationMessageFor(model => model.Answer) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.OptionValue) %>
        </div>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.OptionValue) %>
            <%: Html.ValidationMessageFor(model => model.OptionValue) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.completedBy) %>
        </div>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.completedBy) %>
            <%: Html.ValidationMessageFor(model => model.completedBy) %>
        </div>

        Option Required: <%:Html.TextBoxFor(model=>model.OptionRequired) %>
        Answer Required: <%: Html.TextBoxFor(model=>Model.AnswerRequired) %>

    </fieldset>

Edit(GET) Action:

        public ActionResult Edit(string AcadPeriod, string ClassificationID, string ReviewID, int CategoryID)
    {
        Reviewer.Models.ReviewEditModel dset1 = rr.GetReviewEditModel(AcadPeriod, ReviewID, CategoryID.ToString(), ClassificationID);
        return View(dset1);
    }

Edit(POST) Action:

        [HttpPost]
    public ActionResult Edit(Reviewer.Models.ReviewEditModel model)
    {
        try
        {
            foreach (Reviewer.Models.QuestionEditModel qem in model.Questions)
            {
                if (qem.Answer == null || qem.OptionValue == null) { qem.completedBy = this.HttpContext.User.Identity.Name; }
            }

            if (ModelState.IsValid)
            {
                rr.SaveReviewEditModel(model);

                return RedirectToAction("Index");
            }
            else { return View(model); }
            }
        catch
        {
            return View(model);
        }
    }
  • 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-16T12:24:09+00:00Added an answer on May 16, 2026 at 12:24 pm

    You have to tell it what to actually render (<%: %>):

    <% foreach (Reviewer.Models.QuestionEditModel qem in Model.Questions) { %>
         <%: Html.EditorFor(q=>qem, qem.EntryType, null) %>
    <% } %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.