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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:16:46+00:00 2026-05-18T08:16:46+00:00

Anyone know how you can call a functional equivalent to Html.EditorFor() from the Controller?

  • 0

Anyone know how you can call a functional equivalent to Html.EditorFor() from the Controller?

I have a standard table in my View. The rows make use of an EditorTemplate

<table id="tableOfBar">
    <tfoot>
        <tr><td colspan="2">Some paging controls and whatnot</td></tr>
    </tfoot>
    <tbody>
        <% for (int i=0;i<Model.Rows.Count();i++)
           {
               int j = i;
        %><%: Html.EditorFor(m => m.Rows[j], "FooRowTemplate", "Rows["+j+"]", new { OtherViewDataStuff})%>
    </tbody>
</table>

The editor template is a strongly typed partial view that returns the <tr> and child elements.

All this works fine, but the next step is adding an “Add Row” button. For a bunch of reasons that are out of scope here, I want to hit the server rather than a purely client-side solution. What I’d am trying to do is return the EditorTemplate as a Partial View and have JavaScript take that returned Html and append it to the table.

[HttpPost]
public ActionResult AddRow(FooModel model)
{
    var row = new FooRowModel();
    model.AddRow(row);
    var index = model.Rows.IndexOf(row);
    return PartialView("~/Areas/MyArea/Views/Shared/EditorTemplates/FooRowTemplate.ascx", model.Rows[index]);
}

All of THAT works fine EXCEPT the input naming. The part that is missing is collection prefix stuff that tells the Model Binder how to reassemble the model on post back. On the View side, you can specify what this should be (that is the "Rows["+j+"]" part of the EditorFor() call above).

Can you give a Partial View a html field name prefix like with EditorFor()? Any thoughts on how to make this work? My whole approach may be totally wrong, that’s fine. Just tell me why. 🙂

Thanks for your help.

  • 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-18T08:16:47+00:00Added an answer on May 18, 2026 at 8:16 am

    I would recommend you reading the following blog post which explains in details how to achieve what you are looking for.

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

Sidebar

Related Questions

No related questions found

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.