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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:52:08+00:00 2026-06-03T09:52:08+00:00

I have an input, type text, element which is being validated using MVC3 validation

  • 0

I have an input, type text, element which is being validated using MVC3 validation on the client and I’d like to not have the input value sent to the server when the post occurs.

I have two entities: A “File” entity and a “Company” entity which share a 1 to 1 relationship. The file entity has a CompanyId foreign key.

This is why if you look at the name and id attributes they appear as: File.Company.Code or File_Company_Code.

The reason I want to avoid sending the input value back to the server is when the request reaches the server I only want to bind the values to my entity of type “File”. As it is also receiving a value for “File.Company.Code” it is also attemting to bind the values to the File’s company object, which is what I want to avoid.

The input element is :

    <input name="File.Company.Code" id="File_Company_Code" type="text" data-val-required="Se requiere un c&#243;digo de cliente." data-val="true" value=""/>

    And the span element:
    <span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for=" File.Company.Code "/>

I’ve tried:
-Changing the input name and span data-valmsg-for attributes using jquery. But I think that after doing this I may need to rebind the validators??

Any suggestions? (I hope to have explained myself clearly if not let me know.)
Thanks

UPDATE 1 **
Thanks to AFinkelstein sugestion which put me on the right track I updated my domain model such as:

public class FileModel {

        public File File {
            get {
                return this.file;
            }
        }

        *** ADDED this which helped me solve the problem ***
        public Company Company {
            get {
                return this.file.Company;
            }
        }
    }

In my view instead of doing :

 @Html.TextboxFor(model => model.File.Company.Code)  
  @Html.ValidationMessageFor(model => model.File.Company.Code)

I now do:

  @Html.TextboxFor(model => model.Company.Code)  
  @Html.ValidationMessageFor(model => model.Company.Code)

This way the generated name and Id attributes have the value: Company.Code and Company_Code, they dont have the preceding “File”. When I receive the post on the server and bind the values to the File object:

 FileModel fileModel = new FileModel();
            try {

                TryUpdateModel(fileModel.File, "File");

as it is not receiving a value for “File.Company.Code” it doesnt attempt to initialize the file’s “Company” object, which was causing me other problems.

  • 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-03T09:52:09+00:00Added an answer on June 3, 2026 at 9:52 am

    As it is also receiving a value for “File.Company.Code” it is also attemting to bind the values to the File’s company object, which is what I want to avoid.

    I presume this means that File is a domain model within your project. I recommend using a view model in your view.

    public class FileViewModel
    {
        //other stuff contained within the File class
    
        [Required]
        public string FileCompanyCode { get; set: }
    }
    

    You can use your view model to create or refetch your actual File after posting. Just don’t set your actual file company object to the file company code property in the view model. This way it doesn’t actually matter if your file company code is binded or not.

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

Sidebar

Related Questions

I have an INPUT element of the TEXT type and I want to perform
I have an input of type text , from which I have already entered
for email validation I have these two input fields: <input class=inputbox type=text name=data[subscriber][email] id=field_email
I have the following html: <ul> <li><a href='#'>Item 1</a><input type='text' value='whatever' /></li> <li><a href='#'>Item
I have the following HTML: <input type=email id=email> I want to type text into
I have this input text: <html><head><meta http-equiv=content-type content=text/html; charset=utf-8></head><body><table cellspacing=0 cellpadding=0 border=0 align=center width=603>
I just wanted to ask. I have text input to allow users to type
Here's an example of what I mean: I have an array: array('type'=>'text', 'class'=>'input', 'name'=>'username',
I have an input type file element: <input type=file name=val1 /> And jquery: $(input[name='val1']).off(click);
I have a template like script type: text/template, id: list-template, ''' <div class=display> <div

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.