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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:43:31+00:00 2026-05-24T02:43:31+00:00

I could have used @Html.HiddenFor(x=> ViewData[crn]) but, I get, <input id=ViewData_crn_ name=ViewData[crn] type=hidden value=500

  • 0

I could have used

@Html.HiddenFor(x=> ViewData["crn"])

but, I get,

<input id="ViewData_crn_" name="ViewData[crn]" type="hidden" value="500" />

To somehow circumvent that issue(id=ViewData_crn_ and name=ViewData[crn]), I tried doing the following, but the “value” attribute isn’t getting set.

@Html.HiddenFor(x => x.CRN, new { @value="1"})
@Html.HiddenFor(x => x.CRN, new { @Value="1"})

generates

<input id="CRN" name="CRN" type="hidden" value="" />
<input Value="500" id="CRN" name="CRN" type="hidden" value="" />

Am I doing anything wrong??
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-05-24T02:43:32+00:00Added an answer on May 24, 2026 at 2:43 am

    Have you tried using a view model instead of ViewData? Strongly typed helpers that end with For and take a lambda expression cannot work with weakly typed structures such as ViewData.

    Personally I don’t use ViewData/ViewBag. I define view models and have my controller actions pass those view models to my views.

    For example in your case I would define a view model:

    public class MyViewModel
    {
        [HiddenInput(DisplayValue = false)]
        public string CRN { get; set; }
    }
    

    have my controller action populate this view model:

    public ActionResult Index()
    {
        var model = new MyViewModel
        {
            CRN = "foo bar"
        };
        return View(model);
    }
    

    and then have my strongly typed view simply use an EditorFor helper:

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

    which would generate me:

    <input id="CRN" name="CRN" type="hidden" value="foo bar" />
    

    in the resulting HTML.

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

Sidebar

Related Questions

I have used JQuery within my asp.net page. JQuery is working fine. I could
I have a Double which could have a value from around 0.000001 to 1,000,000,000.000
I know I could have an attribute but that's more work than I want
It looks like a problem which could have simple solution, but I haven't found
I have used a scrollTop function in jQuery for navigating to top, but strangely
i have used js to multiply but only 1st row is getting multiplied other
Could anyone explain when should the floated elements get cleared? I have noticed sometimes
I have an InputStream which takes the html file as input parameter. I have
I have successfully used twitter-text.js to convert tweets containing links into clickable HTML before,
Although I have read the documentation on Html.HiddenFor, I've not grasped what is it

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.