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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:25:33+00:00 2026-05-30T23:25:33+00:00

In my MVC program, once the user has submitted an edit form, those values

  • 0

In my MVC program, once the user has submitted an edit form, those values for the object get saved in the model server-side, but the previous values show up in the view.

I know it has to do with MVC’s validation process, where it first checks ModelState before the server side values. The solution I’ve read across the forums is to clear the ModelState. The only problem is, ModelState.Clear isn’t working for me.

Help please.

Model

public class Help
    {
        [HiddenInput(DisplayValue=true)]
        public int HelpID { get; set; }

        [Required(ErrorMessage = "Please enter a proper URL")]
        public string URL { get; set; }

        [Required(ErrorMessage = "Please enter a content description:")]
        [DataType(DataType.MultilineText)]
        public string HelpContent { get; set; }

        /*? 2 properites are nullable*/
        public DateTime? createDateTime { get; set; }
        public DateTime? modifiedDateTime { get; set; }        
    }

Controller

/*Create the admin controller*/
    public class AdminController : Controller
    {
        //declare interface object
        private IHelpRepository repository;

        /*Pass a db interface to controller*/
        public AdminController(IHelpRepository repo)
        {
            repository = repo;
        }

        /*default admin screen. displays help table obs*/
        public ViewResult Index()
        {            
            return View();
        }

        /*Returns add view form*/
        public ActionResult AddForm()
        {            
            return PartialView();            
        }

        /*Will handle the post for the add screen after user has
        submitted add information*/
        [HttpPost]
        [ValidateInput(false)] //this allows admin to place html in field
        public ActionResult AddForm(Help help)
        {           
            if (ModelState.IsValid) //if all fields are validated
            {                
                //set the edit date
                help.createDateTime = DateTime.Now;
                repository.SaveHelp(help);                
                return (null); //return "null" to div so control is given back to main view
            }
            else //there is something wrong. send back to view            
            {
                return PartialView(help);
            }
        }

        /*Returns edit view form, searches for object to edit with id
         if no id provided, 0 by default*/
        public ActionResult EditForm(int helpID = 0)
        {
            Help help = repository.Help.FirstOrDefault(q => q.HelpID == helpID);
            help.HelpContent = System.Web.HttpUtility.HtmlDecode(help.HelpContent);

            return PartialView(help);
        }

        /*Will handle the post for the edit screen after user has
        submitted edit information*/
        [HttpPost]
        [ValidateInput(false)] //this allows admin to place html in field
        public ActionResult EditForm(Help help)
        {



            if (ModelState.IsValid) //if all fields are validated
            {
                //set the edit date
                help.modifiedDateTime = DateTime.Now;
                repository.SaveHelp(help);
                ModelState.Clear();
                return (null); //return "null" to div so control is given back to main view
            }
            else //there is something wrong. send back to view            
            {

                return PartialView(help);
            }
        }

        /*Delete action method, searches with id*/
        [HttpPost]
        public ActionResult Delete(int helpId)
        {
            Help helpDel = repository.Help.FirstOrDefault(p => p.HelpID == helpId);
            if (helpDel != null) //if the object is found, delete
            {
                repository.DeleteHelp(helpDel);
            }

            //in all cases return to index
            return RedirectToAction("Index");
        }

        /*Used by the telerik table to rebind grid*/
        [GridAction]
        public ActionResult AjaxBinding()
        {
            return View(new GridModel(repository.Help));
        }
    }//end admin controller class`

Partial View (Gets loaded into a div)
`

@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "Editx" }))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Edit Entry</legend>
        @Html.HiddenFor(model => model.HelpID)
        <div class="editor-label">
            @Html.LabelFor(model => model.URL)
        </div>
        <div class="editor-field">
           @Html.EditorFor(model => model.URL)
           @Html.ValidationMessageFor(model => model.URL)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.HelpContent, "Help Content")            
        </div>
         <div class="editor-field">
       @{
    Html.Telerik().EditorFor(content => content.HelpContent)
      .Name("HelpContent")
        .FileBrowser(settings => settings
          .Browse("Browse", "ImageBrowser")
          .Thumbnail("Thumbnail", "ImageBrowser")
          .Upload("Upload", "ImageBrowser")
          .DeleteFile("DeleteFile", "ImageBrowser")
          .DeleteDirectory("DeleteDirectory", "ImageBrowser")
          .CreateDirectory("CreateDirectory", "ImageBrowser")
      )
      .Render();
        }
        @Html.ValidationMessageFor(model => model.HelpContent)
        </div>

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

        <div class="editor-label">
            @Html.LabelFor(model => model.modifiedDateTime, "Modified Date")
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.modifiedDateTime)
            @Html.ValidationMessageFor(model => model.modifiedDateTime)
        </div>
        <p>
            <input id="btnEdit" type="submit" value="Save" />
            <button id="btnCancel">Cancel</button>
        </p>
    </fieldset>
    }
  • 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-30T23:25:34+00:00Added an answer on May 30, 2026 at 11:25 pm

    After trolling through about a hundred links, I found the solution to my problem. ModelState.Clear actually clears the objects values in the controller, but for whatever reason was still displaying the old values in the view. Maybe its because I load/unload my edit form into a div tag? Don’t ask. I don’t know. The solution that works for me is this:

    $.ajax({ 
    url: "somecontroller/someAction,
    cache: false, // this is key to make sure JQUERY does not cache your request
    success: function( data ) {
    alert( data ); } }); 
    

    I had to set the “cache” setting to “false”.

    Thanks to @minus4 for the solution, bruh.

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

Sidebar

Related Questions

I am serializing an object in my ASP.net MVC program to an xml string
I know how to write program in PHP and implementation of MVC model. but
Suppose each user has certain preferences that is saved in database for that user.
I'm about to program a mutistep form in my MVC App (Self-made MVC framework)
I have a phone-book program written in C++, that uses the MVC model, now
I am trying to program in MVC architecture. So, I have one HTML form
My program uses MVC. When the user hits New File, I need to check
I have a program designed as an MVC-pattern, where my model extends AbstractListModel. When
I am familiar with MVC/MVP though my question is simple, I'm about to program
MVC use action attributes to map the same view for http get or post:

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.