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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:39:50+00:00 2026-05-28T05:39:50+00:00

I have created the following view for users to create new items. Ive tried

  • 0

I have created the following view for users to create new items. Ive tried to create a bit of validation so if the user leaves a field blank, then it produces a validation message. However, if the user does leave a field blank, my application crashes on the following line: _headline = structuralObject.SetValidValue(value, false) in the Model.Designer.cs file. because:

This property cannot be set to a null value.

Part of my Model.Designer.cs file:

[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.String headline
    {
        get
        {
            return _headline;
        }
        set
        {
            OnheadlineChanging(value);
            ReportPropertyChanging("headline");
      _headline = StructuralObject.SetValidValue(value, false);
            ReportPropertyChanged("headline");
            OnheadlineChanged();
        }
    }

The section of code this applies to is as follows in my Create View:

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)

<fieldset>

    <legend>News Details</legend>

    <br />
        Posted Date:
            <div class="editor-field">
                @Html.EditorFor(model => model.posted)
                @Html.ValidationMessageFor(model => model.posted)
            </div>

    <br />

        Headline Title:
            <div class="editor-field">
                @Html.EditorFor(model => model.headline)
                @Html.ValidationMessageFor(model => model.headline)
            </div>

    <br />

The following is my AccountModels.cs file where i entered the validation for the View:

[MetadataType(typeof(NewsValidation))]

public partial class News
{
}

public class NewsValidation
{

   [Required(ErrorMessage = "Posted date is required")]
    public DateTime posted { get; set; }

    [Required(ErrorMessage = "Headline is required")]
    [Display(Name = "Headline")]
    public string headline { get; set; }

    [Required(ErrorMessage = "Story body is required")]
   public string story { get; set; }
}

I was told it was because my database allowed Null values however since then i have created a new database which no longer allows Nulls. My application still crashes and dont know where to start. Here’s the odd thing, when it crashes, i click play for it to continue, and the validation appears. So it looks like the validation works but for some reason by application crashes beforehand.

Can anyone offer any support?

  • 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-28T05:39:51+00:00Added an answer on May 28, 2026 at 5:39 am

    The problem is that the setter of the headline property on your domain model is attempting to perform the update. This setter is invoked by the default model binder when it attempts to bind the action argument from the request. And if the user leaves the headlines field blank you will get this exception.

    I would very strongly recommend you using view models and never passing your domain models to the view. So define a simple NewsViewModel:

    public class NewsViewModel
    {
        public DateTime Posted { get; set; }
    
        [Required]
        public string Headline { get; set; }
    }
    

    and then have your controller action pass it to the view:

    public class HeadlinesController: Controller
    {
        public ActionResult Index()
        {
            var model = new NewsViewModel();
            return View(model);
        }
    
        [HttpPost]
        public ActionResult Index(NewsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                // there were validation errors. For example the user
                // left the headline field blank => redisplay the view
                return View(model);
            }
    
            // at this stage we know that validation passed => we can 
            // process our domain model.
            var news = new News();
            news.posted = model.Posted;
            news.headline = model.Headline;
    
            return RedirectToAction("success");
        }
    }
    

    and obviously the view will be now strongly typed to your view model:

    @model NewsViewModel
    @using (Html.BeginForm()) 
    {
        @Html.ValidationSummary(true)
        <fieldset>
            <legend>News Details</legend>
    
            <br />
            Posted Date:
            <div class="editor-field">
                @Html.EditorFor(model => model.Posted)
                @Html.ValidationMessageFor(model => model.Posted)
            </div>
    
            <br />
    
            Headline Title:
            <div class="editor-field">
                @Html.EditorFor(model => model.Headline)
                @Html.ValidationMessageFor(model => model.Headline)
            </div>
    
            <br />
    
            <button type="submit">OK</submit>
        </fieldset>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In views.py I have the following view which gets called when a new user
I have created an alert view with two buttons using the following code: UIAlertView
If i have a controller action Create that returns a view with the following
I have created the following stored procedure.. CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP] ( @CODE CHAR(5) ,
I have created the following project structure for my new asp.net mvc project any
I have created an indexed view: CREATE VIEW LogValueTexts WITH SCHEMABINDING AS SELECT ISNULL(LRVS_SLOG_ID*256+LRVS_IDX,0)
I have a general create function that submits a new user to the database
I have created following rule in the .htaccess file located at the root of
I have created the following C library for reading an image: typedef struct {
I have created the following vsct file xml. <?xml version=1.0 encoding=utf-8?> <CommandTable xmlns=http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable xmlns:xs=http://www.w3.org/2001/XMLSchema>

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.