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 8254213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:06:55+00:00 2026-06-08T01:06:55+00:00

I’ve got troubles with MVC4 and Editor Templates when I get the post back

  • 0

I’ve got troubles with MVC4 and Editor Templates when I get the post back after press the submit button.
This is my model :

public class Form
{
    public Form()
    {
        this.Rows = new List<Row>();
    }

    public List<Row> Rows { get; set; }

    public int Id { get; set; }
}

public class Row
{
    public Row()
    {
        this.Label = string.Empty;
        this.Type = string.Empty;
    }

    public string Label { get; set; }

    public string Type { get; set; }

    public int Id { get; set; }
}

public class SimpleRow : Row
{
    public SimpleRow()
    {
        this.Value = string.Empty;
    }

    public string Value { get; set; }
}

public class DropDownRow : Row
{
    public DropDownRow()
    {
        this.Content = new List<ContentDropDown>();
    }

    public List<ContentDropDown> Content { get; set; }
}

public class ContentDropDown
{
    public ContentDropDown()
    {
        this.Title = string.Empty;
        this.Selected = false;
    }

    public string Title { get; set; }

    public bool Selected { get; set; }

    public int Id { get; set; }
}

This is my controller :

public class FormController : Controller
{
    [Authorize]
    public ActionResult Index()
    {
        return this.View();
    }

    [HttpPost]
    [Authorize]
    public ActionResult Index(HttpPostedFileBase file)
    {
        this.ViewBag.Title = "Formulaire Collaborateur";

        if (file != null && file.ContentLength > 0)
        {
            return this.View(SerialisationHelper.DeserializeFromStream<Form>(file.InputStream));
        }

        return this.View();
    }

    [HttpPost]
    [Authorize]
    public ActionResult EmailForm(Form updatedForm)
    {
        Form f = updatedForm; // Here, The parameter updatedForm have just is first row filled with empty strings and the other rows null

        return this.View("Index");
    }
}

My Index.cshtml :

@model Utils.FormObject.Form
@{
    ViewBag.Title = "Index";

}
@using (Html.BeginForm("EmailForm", "Form", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <fieldset>
        <p>
            @for (int i = 0; i < Model.Rows.Count; i++)
            {
                @Html.HiddenFor(x => x.Id)
                @Html.EditorFor(x => x.Rows[i])    
            }
        </p>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
    <br />
}

my others views in a sub-folder called EditorTemplates :
Row :

@model Utils.FormObject.Row
@{
    ViewBag.Title = "Row";
}
@Html.HiddenFor(x => x.Id)
@Html.EditorFor(x => x)

SimpleRow :

@model Utils.FormObject.SimpleRow

@{
    if (Model.Type.Equals("String"))
    {
        <br />
        @Html.HiddenFor(x => x.Id)
        @Html.DisplayFor(modelItem => modelItem.Label)
        @Html.EditorFor(modelItem => modelItem.Value)
    }
    <br/>
}

DropDownRow :

@model Utils.FormObject.DropDownRow
@{
    ViewBag.Title = "DropDownRow";
}
@* @Html.DropDownListFor(x => x, new SelectList(Model.Content, "Title", "Title"))*@
@{
    @Html.HiddenFor(x => x.Id)
    @Html.LabelFor(item => item.Label)
    var list = new List<SelectListItem> { new SelectListItem { Value = string.Empty, Text = "--please select--", Selected = false } };
    foreach (var row in Model.Content)
    {
        list.Add(new SelectListItem { Text = row.Title, Selected = row.Selected });
    }
    @Html.DropDownListFor(x => x, list)
}

and ContentDropDownRow :

@model Utils.FormObject.ContentDropDown
@{
    ViewBag.Title = "ContentDropDown";
}
@Html.HiddenFor(x => x.Id)
@Html.LabelFor(x => x.Title)

My Form is approximately well displayed (in fact the label of the dropdown lists are displaying ‘Label’ instead of the Label of the property …). The problem is when I press the submit button the post back value ‘updatedForm’ is not filled. The first row Row[0] have its labels filled by empty strings and the others rows are null.
I tried this but I didn’t managed to make it works.

I’m a little lost here, I don’t understand why it refuse to work.

PuK

  • 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-06-08T01:06:58+00:00Added an answer on June 8, 2026 at 1:06 am

    You seem to be using an Editor Template to render your Row objects but I don’t think you’re using it correctly. If you have an Editor Template for a single Row object you just need to render the Row collection from your Index.cshtml by passing the collection to the template. Here’s an Editor Template for your Row:

    @model Utils.FormObject.Row
    @{
        ViewBag.Title = "Row";
    }
    @Html.HiddenFor(x => x.Id)
    @Html.EditorFor(x => x.Label)
    @Html.EditorFor(x => x.Type)
    

    Render the Row collection from the Index.cshtml view – no need to loop as the Editor Template will automagically render each Row in the collection and name them correctly:

    @model Utils.FormObject.Form
    @{
        ViewBag.Title = "Index";
    }
    <fieldset>
        <p>
            @Html.HiddenFor(x => x.Id)
            @Html.EditorFor(x => x.Rows)    
        </p>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
    

    This should create fields like below which will be correctly named and bound as part of your Form object when posted back to your Controller:

    Rows[0].Id
    Rows[0].Label
    Rows[0].Type
    Rows[1].Id
    Rows[1].Label
    Rows[1].Type
    

    See my answer to this question:

    Pass values from multiple partial views

    Small write up on Editor Templates here:

    codenodes.wordpress.com – MVC3 Editor Templates

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
i got an object with contents of html markup in it, for example: string
Does anyone know how can I replace this 2 symbol below from the string

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.