How to clear the fields after submitting a form in MVC?

How to clear the fields after submitting a form in MVC?, someone asked me to explain?

button onclick submit form


In this article, I will show you how to clear form after submit in MVC. Before, when I submitting the mvc form; the page fields are not cleared; the problem on resetting of all form fields. But the page still have the values.

This is due to HTML helpers, It will completely ignore the model class. So that we need to clear the class and return view. After this, It worked perfectly.

Here, I used contact class.


Contact class: 

public class Contact
        public string Name { get; set; }

Required, EmailAddress]
        public string Email { get; set; }

        public string Subject { get; set; }

       public string Body { get; set; }



       public ActionResult Save(Contact contact)
            //Save data to DB here ...         

            Contact ObjContact = new Contact() { Name = string.Empty, Email = string.Empty, Subject = string.Empty, Body = string.Empty };
            return View("Index", ObjContact);



Post your comments / questions