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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:42:21+00:00 2026-05-20T10:42:21+00:00

I am sorry if this has been asked already, but I have been looking

  • 0

I am sorry if this has been asked already, but I have been looking for sometime but all I have found are rather old posts (mvc1, mvc2).
I have a form which I would like to submit via Ajax.

This looks like it would work but does not cover server side validation.

1) I am unsure if I should use the AjaxHelper.BeginForm or use raw jquery calls ($.ajax)? What is the recommended approach here?

2) How do I handle client and server side validation? I am hoping the mvc framework provides a built in mechanism for dealing with this?
There are some validations which I am only doing server side. Would using a ValidationSummary still work here?

I am using asp.net mvc3/razor with unobtrussive javascript validation.

Thank you!

Edit: (as requested by Bobby B below).
This was added months after asking the question as a user wanted to know how to use AjaxHelper

This is the javascript code I used:

<script type="text/javascript">

function ajaxValidate() {
  return $('form').validate().form();
}

function getGbPostSuccess(ajaxContext){
  // .... it is not necessary to do anything here.
}
function showFaliure(ajaxContext){
   // handle failure
}

HTML snippet:

@using (Ajax.BeginForm("Index", "Home", new AjaxOptions
                        {
                            UpdateTargetId = "form1",
                            InsertionMode = InsertionMode.Replace,
                            OnBegin = "ajaxValidate",
                            OnSuccess = "getGbPostSuccess",
                            OnFailure = "showFaliure"
                        }))
{
  • 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-20T10:42:22+00:00Added an answer on May 20, 2026 at 10:42 am

    I’ve been using malsup’s jQuery form plugin for a while for this purpose. I’m honestly not familiar with AjaxHelper, but does look like it’ll do what you’re looking for. As far as doing both client and server side validation, that should all happen mostly automatically as long as you’re using model binding and the attributes from the System.DataAnnotations namespace.

    public class MyModel
    {
        [Required(ErrorMessage = "Please enter your name")]
        public String Name { get; set; }
    
        [Required(ErrorMessage = "Please enter your email")]
        public String Email { get; set; }
    
        [Required(ErrorMessage = "Please enter a rating")]
        [Range(1, 5, ErrorMessage = "The rating must be between 1 and 5")]
        public Int32 Rating { get; set; }
    }
    
    [HttpPost]
    public ActionResult Index(MyModel myModel)
    {
       if(ModelState.IsValid)
       {
           // good to go, put it in the DB or whatever you need to do
       }
       else 
       {
           return View(model); // return the user back to the page, ModelState errors can be viewed using Html.ValidationSummary() or individual Html.ValidationMessageFor() calls
       }
    }
    

    If you’re doing your own custom server-side validation, you can either create your own custom validation attribute by creating an attribute that implements ValidationAttribute, or just add validation errors by calling ModelState.Errors.Add() (or something around there, I don’t have a reference handy)

    For client side, MVC will generate clientside validation for you based on the DataAnnotations attributes on your model.

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

Sidebar

Related Questions

I'm sorry if this question has been asked already, but I couldn't find it
Im very sorry if this has been answered before but I have been looking
Sorry If something like this has already been asked, but I can't find exactly
I am sorry to ask this question when it has already been asked but
all. Sorry if this has been asked and answered already, I couldn't find this
Sorry if this has already been asked, but I just want to make sure
Sorry if this has been asked elsewhere. I have looked but can't find any
Sorry if you feel like this has been asked but I have read the
Sorry if this has already been asked somewhere, but I wasn't able to find
I'm sorry if this has already been asked, but I haven't been able to

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.