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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:53:37+00:00 2026-05-21T02:53:37+00:00

I have a number of custom EditorTemplates for various model classes. Inside these templates

  • 0

I have a number of custom EditorTemplates for various model classes. Inside these templates I obviously need to reference the properties of the model. My problem is that when I use the direct syntax of Model.Id (for example), the value is null. Another example is Model.Name which returns an empty string. However, when I reference the model in an expression (eg. @Html.TextBoxFor(i => i.Name)) then the values are there.

To further illustrate, here is a code snippet:

@model Vigilaris.Booking.Services.CompanyDTO
<div>
    <fieldset class="editfieldset">
        <legend class="titlelegend">Company Details</legend>
        <ol>
            <li>
               @Html.TextBox("tb1", @Model.Id) 
               @Html.TextBox("tb2", @Model.Name) 
            </li>
            <li>
                @Html.LabelFor(i => i.CreatedDate)
                @Html.DisplayFor(i => i.CreatedDate)
            </li>
            <li>
                @Html.LabelFor(i => i.Name)
                @Html.TextBoxFor(i => i.Name)
            </li>
            <li>
                @Html.LabelFor(i => i.Description)
                @Html.TextAreaFor(i => i.Description)
            </li>
            <li>
                @Html.LabelFor(i => i.Phone)
                @Html.TextBoxFor(i => i.Phone)
            </li>
        </ol>
    </fieldset>
</div>  

In this example, all the code that is using the LabelFor and DisplayFor helper functions displays the data from the model. However, the Html.TextBox code portion returns 0 for Model.Id and empty string for Name.

Why does it not access the actual model data when I reference Model directly?

  • 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-21T02:53:37+00:00Added an answer on May 21, 2026 at 2:53 am

    I managed to figure this one out. One thing I left out in my problem description was that I am using Telerik MVC Grid extension and the EditorTemplate is being using for In-form editing. So, the Model properties are not available at this point and this is understandable behaviour. I had to use a client side onEdit event on the Telerik MVC Grid and then set these values as necessary.

    How I remember solving this is that I added a ClientEvent in my Telerik MVC Grid as follows:

    .ClientEvents(events => events.OnEdit("Users_onEdit"))
    

    This tells the grid to run my javascript function called Users_onEdit when an edit is triggered. Then, in my javascript function I find the field I want and then set its value. Here is an code excerpt:

    function Users_onEdit(e) {
        if (e.mode == "insert") {
            $("#UserName").removeAttr("readonly");
            $("#UserName").removeAttr("title");
            $("#divNewUserMessage").show();
    
            var formId = String(e.form.id);
            var formIndex = formId.indexOf("form");
            var companyId = formId.substr(6, formIndex -6);
            var hiddenCompanyId = $(e.form).find("#CompanyId");
            hiddenCompanyId.val(companyId);
        }
    }
    

    I hope this helps others out there.

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

Sidebar

Related Questions

I have a number of custom Item and Project Templates for Visual Studio 2010.
I have a number of public custom Google Maps created via http://maps.google.com/ - obviously
I have a number of custom Exception -inheriting classes in my package, which do
I'm using the Silverlight 3 datagrid and have a number of custom styles applied
I have created custom cell in which there are n number of image views.
I have a simple custom NumberField: class NumberInput(forms.widgets.Input): input_type = 'number' class NumberField(forms.DecimalField): def
I have a number of classes and they are quite close to each other
I have a number of classes (more than 40), each one has a number
I have a number of custom objects of type X. X has a number
i have a repeater that is bound to a number of custom dataitems/types on

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.