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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:16:47+00:00 2026-06-03T20:16:47+00:00

i have created a view like below. <%for (var i = 0; i <

  • 0

i have created a view like below.

<%for (var i = 0; i < Model.customerCDTO.Count();i++)
  {%>
  <tr>
     <td style="text-align: center; width: 10%;" class="table-content-middle">
     <%if (Model.customerCDTO[i].Active == true)
      {%>
      <%=Html.CheckBoxFor(m=>m.customerCDTO[i].Active)%>
      <%}
      else
      { %>
      <%=Html.CheckBoxFor(m => m.customerCDTO[i].Active)%>
    <%} %>
     </td>
     <td class="table-content-middle" align="center" style="width: 80%;">
     <%=Html.DisplayTextFor(m=>m.customerCDTO[i].Name)%>
     </td>
     </tr>
 <%} %>

the problem with the above view is that it is giving value for null for customerCDTO[i].Name

below is my view model

public class CustomerVM
{
public List<CustomerCDTO> customerCDTO { get; set; }
}

In the above view model I have created a List property. The CustomerCDTO class definition is as follows.

public class CustomerCDTO
{
public string Name { get; set; }
public bool Active { get; set; }
public bool? IsChecked { get; set; }
}

please help.

thanks

  • 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-03T20:16:49+00:00Added an answer on June 3, 2026 at 8:16 pm

    It’s giving you a null value because your form does not contain any <input> elements corresponding to the Name property (which you can immediately spot if you View Source). The reason for this is that DisplayTextFor is not supposed to create such elements in the first place.

    An almost always bad idea would be to also call Html.HiddenFor, which does create input elements:

    <td class="table-content-middle" align="center" style="width: 80%;">
        <%=Html.DisplayFor(m=>m.customerCDTO[i].Name)%>
        <%=Html.HiddenFor(m=>m.customerCDTO[i].Name)%>
    </td>
    

    This would solve your problem, but then the user could simply edit the values with a tool like Firebug and change the value of Name, which you obviously do not want since otherwise you ‘d have presented an <input> element for that. (Note: I also changed DisplayTextFor to DisplayFor, which in general is the more correct way to do things).

    But what to do then? Well, there’s no magic solution here. If the form doesn’t contain Name then it will be null, but if it does contain Name (even hidden) then the user can change it at will. If that’s a problem, the only option is to modify your backend code to populate Name from your data store.

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

Sidebar

Related Questions

I have a view model something like below, when onAfterRender is fired by Knockout
if i have created a view model and have a partial form that is
I have created a class doing some jobs like GridView inherit from System.Web.UI.WebControls.WebControl. public
I have created a button in my screen's XML like this: <Button android:text=Lets Get
I have a form view model class that populates Select Lists for use by
I have created a partial view, the element in the partial view looks like
i have created a function in controllerappdelegate.m like below - (void) ChangeLabelText:(NSString *)SenderP {
I have created View A and View B. My window has View A displayed
I have created navigaton view using Sencha touch 2. Navigation view has list component
I have created a View which prompts the user to input some records with

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.