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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:01:05+00:00 2026-06-08T02:01:05+00:00

Im trying to validate a popup in my ASP.net MVC 3 application. Ive searched

  • 0

Im trying to validate a popup in my ASP.net MVC 3 application. Ive searched the web for a solution, but have yet to get any of them to work.

I have the following, very simple model:

public class Player
{
    public int playerId { get; set; }

    [Required]
    [Range(0, 99)]
    public int number { get; set; }

    [DisplayName("First Name")]
    [Required]
    [StringLength(15)]
    public string firstName { get; set; }

    [DisplayName("Last Name")]
    [Required]
    [StringLength(15)]
    public string lastName { get; set; }

    [Required]
    public float battingAverage { get; set; }
}

I then have the following view which takes a list of players. Here i’m using a Jquery popup to create or edit a player. The player is then appended to the list in this view.

 @model IEnumerable<PlayingWithJSON.Models.Player>

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>
  <div id="PlayerListBlock"></div>
  <span class="AddLink ButtonLink">Add New Player</span>
  <div id="PlayerDialog" title="" class="Hidden"></div>

<script type="text/javascript">
    $(function () {
      $("#PlayerDialog").dialog(
      {
          autoOpen: false, width: 400, height: 500, modal: true,
          buttons:
              {
                  "Save": function () {
                      if ($("#PlayerForm").valid()) {
                          $.post("/Player/Save",
                                  $("#PlayerForm").serialize(),
                                  function (data) {
                                      $("#PlayerDialog").dialog("close");
                                      $("#PlayerListBlock").html(data);
                                  }
                                );
                      }
                  },
                  Cancel: function () { $(this).dialog("close"); }
              }
    });
    $(".EditLink").live("click", function () {
        var id = $(this).attr("playerid");
        $("#PlayerDialog").html("")
            .dialog("option", "title", "Edit Player")
            .load("/Player/Edit/" + id, function () { $("#PlayerDialog").dialog("open"); });
    });
    $(".AddLink").click(function () {
        $("#PlayerDialog").html("")
            .dialog("option", "title", "Add Player")
            .load("/Player/Create", function () { $("#PlayerDialog").dialog("open"); });
    });
    LoadList();
});
function LoadList() {
    $("#PlayerListBlock").load("/Player/List");
}
</script>

Below is the partial view which corresponds to the popup that allows me to create and edit a player.

@model PlayingWithJSON.Models.Player

@using(Html.BeginForm("Save", "Player", FormMethod.Post, new { id = "PlayerForm" })) 
{
    @Html.ValidationSummary(true)
    @Html.Hidden("playerId")
    <label class="Number">
        <span>Number</span><br />
        @Html.TextBoxFor(x => x.number)<br />
        @Html.ValidationMessageFor(x => x.number)
    </label>
    <label class="FirstName">
        <span>First Name</span><br />
        @Html.TextBoxFor(x => x.firstName)
        @Html.ValidationMessageFor( x => x.firstName )
    </label>
    <label class="LastName">
        <span>Last Name</span>
        @Html.TextBoxFor(x => x.lastName)
        @Html.ValidationMessageFor( x => x.lastName )
    </label>
    <label class="BattingAverage">
        <span>Batting Average</span>
        @Html.TextBoxFor(x => x.battingAverage)
        @Html.ValidationMessageFor( x => x.battingAverage )
    </label>
}
    <script type="text/javascript">
        $(function () {
            $.validator.unobtrusive.parse("PlayerForm");
        });
    </script>

At the bottom of this form I’ve added a call to validator.unobtrusive.parse, but have yet to get that to work.

Here is the save method in the controller:

[HttpPost]
public ActionResult Save(Player player)
{
    if (ModelState.IsValid)
    {
        //Save Stuff
        baseBall.Players.Add(player);
        baseBall.SaveChanges();
        return PartialView("List", baseBall.Players.ToList());
    }
    else
        return PartialView("PlayerForm", player);
}

When I hit the “save” button on the popup, none of the client side validation occurs. The jquery I’ve written so far works fine, but how to I include validation? I’ve read validation belongs in the partial, but i’ve also read validation belongs in the “main view”. What i’m hoping someone can do is show me how to correctly validate the content in the popup.

  • 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-08T02:01:08+00:00Added an answer on June 8, 2026 at 2:01 am

    You need to add the $.validator.unobtrusive.parse("PlayerForm"); to a function that you call on successful display of the dialog box. You are currently putting it in document.ready, which isn’t called at the point because the page has already been loaded. In my application I am opening the dialogs from Ajax.ActionLink, so I put it in the OnSuccess callback of the link. I am not 100% sure where you need to put it in your application, but I hope this gives you enough to go on to resolve the issue.

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

Sidebar

Related Questions

I'm trying to validate an XML file, but I get the following error: Can
I have been trying to validate my web page for the last two hours,
Im trying to validate my XML file with an external DTD. But I get
When trying to validate my site, I get the following error: Line 188, column
While trying to validate my forms i get the following error: Expected a {
While trying to validate form data on my page i get the following error:
I'm trying to validate an ID. I have this class called ManejadorTickets in which
I am trying to validate a text field for valid date (MM/DD/YYYY) I have
I have an application and I'm trying to make sure it's running in a
I'm trying to validate and get an interest rate from user input. I'm wanting

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.