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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:15:49+00:00 2026-06-03T15:15:49+00:00

I have a page on my MVC application where a user can edit /

  • 0

I have a page on my MVC application where a user can edit / upload data to a database.

Basically the have a link on the site called “Admin”, they click here, logon and are presented with a page that allows them to change / update data displayed on the “Special Offers” section of the site.

The “Admin” section contains a few textareas which display data contained in a database table. The user can then change the data displayed in these text areas and click an “Update” button which will then upload this data to the database, then the “Special Offers” page in the site displays this newly updated data to the public.

The issue I have is that if the user who is editing the data tries to update the database with textareas that that are empty of data then the “Special Offers” page will not load (it returns an error shown below). I have checked that the database table has the “Nullable” option set to “True”, but this makes no difference.

[Error]

Server Error in ‘/’ Application.

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:

Line 25: @Html.Raw(tbl_special_offers.offer3.Replace(Environment.NewLine, "<br/>"))

This is the code that the “Special Offers” View uses to access the database and display the data (using Visual Web Developer Express):

@model IEnumerable<bhgc.Models.tbl_special_offers>
@{
    ViewBag.Title = "Special Offers";
}
<div>
    <fieldset>
            <legend>Special Offers</legend>
        <br />
        @foreach (var tbl_special_offers in Model)
        {

            <div style="overflow: hidden; width: 100%;">
                <div style="float: left; width: 40%; height: 50%; margin-left: 50px; border: 1px solid #ddd;  padding: 15px;">
                    @Html.Raw(tbl_special_offers.offer1.Replace(Environment.NewLine, "    <br/>"))
                </div>
                <div style="float: right; width: 40%; height: 50%; margin-right: 50px; border: 1px solid #ddd; padding: 15px;">
                    @Html.Raw(tbl_special_offers.offer2.Replace(Environment.NewLine, "    <br/>"))
                </div>
            </div>


    }
    </fieldset>
</div>

Is there anyway to either allow the field to be empty, or automatically append a space into the field when it is updated so that when the public view the “Special Offers” page it doesn’t return an error?

The website and page in question is currently public at http://www.boarsheadgolfcentre.co.uk/Home/Special

Many 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-06-03T15:15:52+00:00Added an answer on June 3, 2026 at 3:15 pm

    Since the item you are performing a Replace on null, why don’t you try something like this

    (tbl_special_offers.offer2 ?? String.Empty).Replace(...)
    

    That way you shouldn’t be replacing on null, and will (hopefully) avoid the exception.

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

Sidebar

Related Questions

I have a MVC application that reads some data from a database and loads
In my MVC application I have a page for a user editing their account
I have a textarea in an ASP.NET MVC Application where the user can type
I have a silverlight app on an MVC page that user's can draw on,
I am working with an ASP.NET MVC application. I have one master page having
I have an ASP.NET MVC Page with a button called Start Live Meeting. When
I have a search page on my MVC site that contains a list of
I have an ASP.NET MVC 2 application which in part allows a user to
I have an ASP.Net MVC application. I am trying to post data to an
I have a form in my MVC application that in theory should submit data

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.