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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:46:40+00:00 2026-06-17T22:46:40+00:00

I am trying to resolve an issue with the following scenario: User loads page

  • 0

I am trying to resolve an issue with the following scenario:

  • User loads page and an EditorTemplate ViewModel is loaded.
  • User opens a dialog over the page.
  • This dialog loads the same EditorTemplate ViewModel inside of it.
  • Control IDs are now non-unique due to multiple instances of each control existing in the DOM Tree

My solution for this is to indicate to my controller that I wish to build the ViewModel inside of a Dialog. I do so by indicating a “prefix” string which should be appended onto generated control IDs. I’ve taken this suggestion from this StackOverflow post.

As such, I have a control declared in my ViewModel as such:

<%--This will append our model's prefix onto all generated IDs to ensure uniqueness.--%>
<% using (Html.BeginHtmlFieldPrefixScope(Model.Prefix)) { %>
<div class="detailsRow required">
    <%= Html.LabelFor(model => model.Name, Model.NameLabel) %>
    <%= Html.EditorFor(model => model.Name) %>
</div>
<% } %>

and in my model:

public NewOrderDetailsModel(string prefix) : this()
{
    Prefix = prefix;
}

This works OK. It has the effect of modifying the control’s ID. It renders as ‘prefix_Name’ not ‘Name.’

However, when I post my data to the server — my changes break MVC’s conversion magic:

enter image description here

As you can see, all the properties which had their ID modified come back as null.

Two-part question:

  • Is this the right path to be going down to achieve my desired effect?
  • How can I inform MVC that the IDs have been modified such that I get the JSON-to-Model conversion back?
  • 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-17T22:46:41+00:00Added an answer on June 17, 2026 at 10:46 pm

    The MVC Conversion Magic you speak of is done using the MVC Model Binder. The default model binder will not handle the prefix in this way since it was not made aware of the prefix’s existence. You can make it aware by annotating the controller action like so:

    public ActionResult SomeAction([Bind(Prefix = "SomePrefix")] ViewModel model){...}
    

    For more information on this, see this post:
    ASP.NET MVC 3 Model-binding and form fields

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

Sidebar

Related Questions

The issue I am trying to resolve is the following: The C++ serial code
I am going nuts here trying to resolve a cascading update/delete issue :-) I
In my efforts to resolve Python issue 1578269 , I've been working on trying
I'm trying to create a patch for cf.vim to resolve an issue with hashes.
I'm trying to figure out how to resolve relatively referenced resources inside dynamically loaded
I have got one issue. Can some one please help me to resolve this?
Im trying to resolve an issue where when using NHibernate with a SqlServerCeDriver that
I am trying get currently focused component id. For this I used following jQuery:
I've tried for hours to resolve this issue. I would sincerely appreciate some help.
[Update:] i know the problem... but need help to resolve this. The issue is

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.