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

  • Home
  • SEARCH
  • 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 789189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:29:02+00:00 2026-05-14T21:29:02+00:00

I am using jQuery1.4.2, ASP.NET MVC 2 and jQuery.UI-1.8. I am creating a data

  • 0

I am using jQuery1.4.2, ASP.NET MVC 2 and jQuery.UI-1.8.

I am creating a data input dialog which works OK when all the data is valid, but I want to validate the input data on the server and return an error to the dialog describing the error and I am not quite sure how to do that and keep the dialog open. The dialog is opened when a link is clicked. The solution may be to try to bypass more of the MVC framework’s default binding that handles the submit button clicks and creates the expected ProfilePermission object and calls the Controller’s AddPermission POST Action method, but I was hoping there may be an easier way without having to write more jquery/javascript code to handle the button clicks and pass the data to/from the server.

My script code looks like

$("#dialog").dialog({ modal: true,
    position: ['center', 180],
    width: 500,
    height: 130,
    autoOpen: false
});

$(".addPermissionDialog").click(function (event) {
    event.preventDefault();
    $("#dialog").dialog('open');
    return false;
});

My View

<div id="dialog" title="Add Permission">
<%: Html.ValidationSummary("") %>
<% using (Html.BeginForm("AddPermission", "Profile"))
{ %>
    <%: Html.Hidden("PersonId") %>
    <%: Html.Hidden("ProfileId") %>
    <div class="editor-label">
        <label for="PersonName">User Name:</label>
        <%: Html.TextBox("PersonName")%>
        <label for="PermissionType">Permission:</label>
        <select name="PermissionTypeId" id="PermissionTypeId" >
            <option value="2">Edit</option>
            <option value="3">View</option>
        </select>
    </div>
    <br />
    <p>
    <input type="submit" name="saveButton" value="Add Permission" />
    <input type="submit" id="cancelButton" name="cancelButton" value="Cancel" />
    <script type="text/javascript">
        document.getElementById("cancelButton").disableValidation = true;
    </script>
    </p>
<% } %>
</div>
<br />
<p>
    <%: Html.ActionLink("Add Permission", "AddPermission", new { profileId = Model.First().ProfileId }, new { @class = "addPermissionDialog" })%>
</p>

My Controller action

    [AcceptVerbs("Post")]
    [HandleError]
    public ActionResult AddPermission(string cancelButton, ProfilePermission profilePermission)
    {
        ViewData["Controller"] = controllerName;
        ViewData["CurrentCategory"] = "AddPermission";
        ViewData["ProfileId"] = profilePermission.ProfileId;

        PermissionTypes permission = repository.GetAccessRights(profilePermission.ProfileId);
        if (permission == PermissionTypes.View || permission == PermissionTypes.None)
        {
            ViewData["Message"] = "You do not have access rights (Edit or Owner permissions) to this profile";
            return View("Error");
        }

        // If cancel return to previous page
        if (cancelButton != null)
        {
            return RedirectToAction("ManagePermissions", new { profileId = profilePermission.ProfileId });
        }

        if (ModelState.IsValid)
        {
            repository.SavePermission(profilePermission);

            return RedirectToAction("ManagePermissions", new { profileId = profilePermission.ProfileId });
        }

        // IF YOU GET HERE THERE WAS AN ERROR
        return PartialView(profilePermission); // The desire is to redisplay the dialog with error message
    }

LATER EDIT
I was hoping for a mechanism to return an error to the dialog using MVC’s plumbing, I eventually broke down and added a save button via the jquery.ui.dialog API and handled the issue that way. I removed the buttons from the .aspx page. I returned return new EmptyResult(); from the controller’s actions if everything worked OK and if there was an error
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Content(errorMessage, MediaTypeNames.Text.Plain);

    // To add a button and bypass more of MVC plumbing
    buttons: {
        "Save": function () {
            var dlg = $(this);
            $.ajax({
                url: "/Profile/AddPermission",
                type: 'POST',
                data: {
                    PersonId: $("#PersonId").val(),
                    ProfileId: $("#ProfileId").val(),
                    PermissionTypeId: $("#PermissionTypeId").val(),
                    PersonName: $("#PersonName").val()
                },
                success: function (data) {
                    dlg.dialog('close');
                },
                error: function (data) {
                    alert(data.responseText);
                }
            });
        }
    }
  • 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-14T21:29:03+00:00Added an answer on May 14, 2026 at 9:29 pm

    I was doing this kind of stuff using jquery.form and jquery dialog;
    in the post action if everything is good you return Content("OK") if not you return the PartialView() (that contains the modelstate errors) after in the function that handles the successful post response you check if it is "OK" close the dialog if not you set the $("#yourDialogDiv").html(responseHtmlThatYouGotFromTheServer)

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

Sidebar

Related Questions

I'm using jQuery and SimpleModal in an ASP.Net project to make some nice dialogs
I am using jQuery to try and trigger a method when an ASP.NET (2.0)
I'm using jQuery UI's draggable and droppable libraries in a simple ASP.NET proof of
I'm trying to execute a asp.net webservice using jquery. When I pass only one
I am building a asp.net webforms (3.5 sp1) application, using jquery where I can
I'm just starting to wean myself from ASP.NET UpdatePanels. I'm using jQuery and jTemplates
Has anyone used jQuery to populate an autocomplete list on a textbox using ASP.NET
I've got this textBox which triggers off an ajax request using jQuery: <asp:TextBox ID=postcodeTextBox
I am using JQuery to post with AJAX to another ASP page. Do I
Using jQuery , how can I dynamically set the size attribute of a select

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.