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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:40:19+00:00 2026-06-03T04:40:19+00:00

I have a strongly typed view inheriting from a POCO class. I want to

  • 0

I have a strongly typed view inheriting from a POCO class. I want to initialize the property of a model with a Querystring value at the time when view loads.

On the View Load I am using ViewData to the save the code :

 public ActionResult Data() { 

    ViewData["QueryStringValue"] = this.Request.QueryString["Param1"]
    return View();

    }

In the HTML markup, I am using this code to initialize the model property in a hidden variable

<%:Html.HiddenFor(m=>m.Param,
Convert.ToInt32(Html.Encode(ViewData["QueryStringValue"]))) %>

m.param is a byte type.

URL of the request is somewhat like this : http://TestApp/Data/AddData?Param1=One

On View Save event, I am using model binding but issue is that I don’t get to see the value of param initialized in the controller. It is always NULL.

My Save Event maps to a controller :

[HttpPost]
public ActionResult SaveData(MyData d)
{
string paramValue = d.Param; //this always returns null

BO.Save(d);
}

I inspected the HTML source and saw that the value of the hidden field itself is blank. Not sure why this is happening since the below code works and shows the param value in a heading element

<h2> <%=Html.Encode(ViewData["QueryStringValue"]) %> </h2>

I have no idea where I am going wrong on this.

  • 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-03T04:40:20+00:00Added an answer on June 3, 2026 at 4:40 am

    Just made this work, Issue is with this line:

     <%:Html.HiddenFor(m=>m.Param,
    Convert.ToInt32(Html.Encode(ViewData["QueryStringValue"]))) %>. I stated in the question that m.Param is of type byte. I figured out that issue was with casting.
    

    I tried this code and it worked

    <%:Html.HiddenFor(m => m.Param, (byte)Convert.ToInt16(this.Request.QueryString["Param1"].ToString()))%>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strongly typed View class that all my UserControls derive from. It
I have a strongly typed view from which I want to insert some data.
i have a strongly typed asp.net-mvc view and the Model has a . Links
I have a utility method which returns a strongly typed value from an old
I have a strongly typed Person view, that I want to render a partial
I have a strongly typed view and want to use it in an NHaml
I have a strongly-typed view that receives a Design model for its rendering. My
I have a strongly typed razor view for a model in my MVC 3
I have a strongly typed view. I get model passed into the view and
I have a ModelA model and a strongly typed view ViewA which is typed

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.