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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:12:43+00:00 2026-05-26T21:12:43+00:00

Alright guys, Need some help! Im working with asp.net mvc3 razor (and am fairly

  • 0

Alright guys, Need some help!

Im working with asp.net mvc3 razor (and am fairly new to it but did lots of web forms)

Okay so onto the problem

My question revolves around submitting a view.
I have a very complicated model that my view is based off (strongly typed).

I want to return the model into the arguments in the HttpPost method of the controller. do basically:

public ActionResult Personal()
    {
        DataModel dataModel = new DataModel();
        FormModel model = new FormModel();
        model.candidateModel = dataModel.candidateModel;
        model.lookupModel = new LookupModel();

        return View(model);
    }

    [HttpPost]
    public ActionResult Personal(FormModel formModel)
    {
        if (ModelState.IsValid)
        {
            //stuff
        }
        return View(formModel);
    }

Now…
I’m having trouble getting values into the formModel parameter on the post method.

This works (meaning i can see the value)but is tedious as i have to write exactly where it sits in a string every single field:

@Html.TextBox("formModel.candidateModel.tblApplicant.FirstName", Model.candidateModel.tblApplicant.FirstName)

It renders like this:

<input name="formModel.candidateModel.tblApplicant.FirstName" id="formModel_candidateModel_tblApplicant_FirstName" type="text" value="Graeme"/>

This doesn’t work:

@Html.TextBoxFor(c => c.candidateModel.tblApplicant.FirstName)

It renders like this:

<input name="candidateModel.tblApplicant.FirstName" id="candidateModel_tblApplicant_FirstName" type="text" value="Graeme"/>

Now I’m assuming the problem lies in the discrepancy of the id’s

So please answer me this:

  1. Am i going about this the right way
  2. Why doesn’t textboxfor get the right value/id, and how do i make it get the right value/id so i can retrieve it in a POST(if that is even the problem)?
  3. Additionally, it seems that textboxfor is restrictive, in the manner that if you have a date time, how do you use the .toshortdate() method? This makes me think textboxfor isn’t useful for me.

Quick clarification:
when i say textboxfor isn’t working, it IS getting values when i GET the form. So they fill, but on the POST / submission, i can’t see them in the formModel in the parameters.

Another side note:
None of the html helpers work, this is the problem. They aren’t appearing in modelstate either.


Thanks everyone for the help

Answer:
html.TextBoxFor and html.Textbox, POSTing values, model in parameters

It was a problem in my view somewhere, i replaced all the code with the snippet in this answer and it worked.

Thank you again

  • 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-26T21:12:43+00:00Added an answer on May 26, 2026 at 9:12 pm

    Am i going about this the right way

    Yes.

    Why doesn’t textboxfor get the right value/id, and how do i make it get the right value/id so i can retrieve it in a POST(if that is even the problem)?

    There is something else in your code that makes this not work. It’s difficult to say since you haven’t shown all your code. Here’s a full working example which illustrates and proves that there’s something else going on with your code:

    Model:

    public class FormModel
    {
        public CandidateModel candidateModel { get; set; }
    }
    
    public class CandidateModel
    {
        public Applicant tblApplicant { get; set; }
    }
    
    public class Applicant
    {
        public string FirstName { get; set; }
    }
    

    Controller:

    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View(new FormModel
            {
                candidateModel = new CandidateModel
                {
                    tblApplicant = new Applicant
                    {
                        FirstName = "fn"
                    }
                }
            });
        }
    
        [HttpPost]
        public ActionResult Index(FormModel formModel)
        {
            // the username will be correctly bound here
            return View(formModel);
        }
    }
    

    View:

    @model FormModel
    @using (Html.BeginForm())
    {
        @Html.EditorFor(c => c.candidateModel.tblApplicant.FirstName)
        <button type="submit">OK</button>
    }
    

    Additionally, it seems that textboxfor is restrictive, in the manner
    that if you have a date time, how do you use the .toshortdate()
    method? This makes me think textboxfor isn’t useful for me.

    I agree that TextBoxFor is restrictive. That’s why I would recommend you always using EditorFor instead of TextBoxFor. It will allow you to simply decorate your view model property with the [DisplayFormat] attribute and voilà. You get any format you like.

    For example:

    public class MyViewModel
    {
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        public DateTime CreatedAt { get; set; }
    }
    

    and in the view:

    @model MyViewModel
    @Html.EditorFor(x => x.CreatedAt)
    

    will format the date exactly as you expect.

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

Sidebar

Related Questions

Alright, this is driving me nuts because my regex is working on Rubular, but
Alright guys, I really hurt my brain over this one and I'm curious if
Alright, this one's interesting. I have a solution, but I don't like it. The
Alright, I hope this isn't too broad a question but my curiosity got the
Alright, hard to phrase an exact title for this question, but here goes... I
Alright, I have a really basic QStandardItemModel , filled with some numbers. I managed
Alright guys, I have looked on the internet for ages and simply could not
Alright, an easy one for you guys. We are using ActiveReport's RichTextBox to display
I need your help, i'm stacked on this project. When i run my applicaion
Alright I'm pretty new to programming and stuff and I'm now trying to code

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.