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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:12:30+00:00 2026-06-14T10:12:30+00:00

I have the following which I want to POST to create when I hit

  • 0

I have the following which I want to POST to create when I hit submit. Only, when I hit submit I get an object reference error referring to my value for the input with id = debugTxt. I suspect that because I’ve lost the object state, I get this error.

So my question is how can I set the text with an initial view that comes from the Model and allow the user to update on POST?

@using (Html.BeginForm("Create", "PhysDoc"))
{
    <table>
        <tr>
           <td class="title">Debug Mode</td>
           <td>
                This input does the initial GET correctly.  On POST I get object ref error related to the value inside @Model.
                <input type="text" id="debugTxt" name="debugModeTxt" value="@Model.DebugMode" />
            </td>  
        </tr>
        <tr>
            <td>
                <input type="submit" value="Submit" />
            </td>
        </tr>
    </table>                
}

Create Method (Note the exception is not thrown here).

    [HttpPost]
    public ActionResult Create(string debugModeTxt)
    {
        PhysdocSettings settings = new PhysdocSettings();
        settings.DebugMode = bool.Parse(debugModeTxt);
        PhysDocSettingsBL settingBL = new PhysDocSettingsBL();
        settingBL.UpdateSettings(settings);
        return View("Index");
    } 

The exception occurs here:

value="@Model.DebugMode" and if I change value="True" my code works fine. But this doesn’t give me an initial value equal to Model.DebugMode.

  • 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-14T10:12:31+00:00Added an answer on June 14, 2026 at 10:12 am

    Try this… Use an HTML helper and specify a default value for the field like so:

    @Html.TextBox("[name]", @Model.DebugMode)
    

    If this doesn’t work can you elaborate on the result?


    You aren’t passing a model to Index when you call return View("Index");. You are merely calling the view and as such you will indeed get a Null Reference Exception.

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

Sidebar

Related Questions

I have the following two queries which I want to get in one query.
I have the following code which will allow only numbers 0-9. But i want
I have the following jQuery which I want to output a list of images.
I have the following code: // Dictionary which I want to optimize Dictionary<string, MyClass>
I have the following php code which I want to add a delay too:
I have the following string from which I want to extract gcc-4.3.2 and C
i have following urls, which i want to find a string and remove that
I want to know is below code correct ? I have following code which
I have XML in the following format which I want to reformat: <blocks> <!--
I have the following query which is working fine, but I also want to

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.