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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:03:52+00:00 2026-06-03T13:03:52+00:00

I’ve just created a new controller, along with its CRUD forms, etc, with a

  • 0

I’ve just created a new controller, along with its CRUD forms, etc, with a database-first EF model/entity.

Its throwing a number of validation errors on save, but since the form has validators, I don’t see why this would be so.

For reasons that are beyond me, I’m not getting any validation to happen at all. It just goes right in to the saveChanges() call, which promptly fails.

Here’s the edit form:

    @model StatementsApplication.DAL.StatementTask

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script>

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

    <fieldset>
        <legend>StatementTask</legend>



        <div class="editor-label">
            @Html.LabelFor(model => model.sInitials)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.sInitials)
            @Html.ValidationMessageFor(model => model.sInitials)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.dtCompleted)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.dtCompleted)
            @Html.ValidationMessageFor(model => model.dtCompleted)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.sGroupLabel)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.sGroupLabel)
            @Html.ValidationMessageFor(model => model.sGroupLabel)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.nGroupSequence)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.nGroupSequence)
            @Html.ValidationMessageFor(model => model.nGroupSequence)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.sTaskType)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.sTaskType)
            @Html.ValidationMessageFor(model => model.sTaskType)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.sTaskLabel)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.sTaskLabel)
            @Html.ValidationMessageFor(model => model.sTaskLabel)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.nTaskSequence)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.nTaskSequence)
            @Html.ValidationMessageFor(model => model.nTaskSequence)
        </div>

        @Html.HiddenFor(model => model.ID)

        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

and here’s the generated model:

namespace StatementsApplication.DAL
{
    using System;
    using System.Collections.Generic;

    public partial class StatementTask
    {
        public int StmtBatchID { get; set; }
        public string sInitials { get; set; }
        public Nullable<System.DateTime> dtCompleted { get; set; }
        public string sGroupLabel { get; set; }
        public double nGroupSequence { get; set; }
        public string sTaskType { get; set; }
        public string sTaskLabel { get; set; }
        public double nTaskSequence { get; set; }
        public int ID { get; set; }

        public virtual StatementBatch tblStmtBatch { get; set; }
    }
}

and here’s the controller bits…

//
// GET: /StatementTask/Edit/5

public ActionResult Edit(int id = 0)
{
    StatementTask statementtask = db.StatementTasks.Find(id);
    if (statementtask == null)
    {
        return HttpNotFound();
    }
    ViewBag.StmtBatchID = new SelectList(db.StatementBatches, "ID", "sStatus", statementtask.StmtBatchID);
    return View(statementtask);
}

//
// POST: /StatementTask/Edit/5

[HttpPost]
public ActionResult Edit(StatementTask statementtask)
{
    if (ModelState.IsValid)
    {
        try
        {
            db.Entry(statementtask).State = EntityState.Modified;
            db.SaveChanges();
        }
        catch (Exception ex) {
            throw ex;
        }
        return RedirectToAction("Index");
    }
    ViewBag.StmtBatchID = new SelectList(db.StatementBatches, "ID", "sStatus", statementtask.StmtBatchID);
    return View(statementtask);
}

Its a matter of some confusion for me as to why sInitials is throwing ‘required’ validation errors, as well as why sGroupLabel is throwing length validation errors.

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-03T13:03:56+00:00Added an answer on June 3, 2026 at 1:03 pm

    a) your model has no data validation annotations. As such, MVC doesn’t do any validation, because you’re not telling it what to validate.

    b) You don’t mention what you are submitting. Are you just submitting an empty form?

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a reasonable size flat file database of text documents mostly saved in
I'm making a simple page using Google Maps API 3. My first. One marker
For some reason, after submitting a string like this Jack’s Spindle from a text
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.