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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:50:18+00:00 2026-06-07T17:50:18+00:00

I am creating an MVC website which makes use of Partial Views on Popups

  • 0

I am creating an MVC website which makes use of Partial Views on Popups to handle all my CRUD transactions. Please note that my application can already handle these CRUD operations perfectly (LINQ-To-Entity). However, I have a problem with my popup forms.

Below is the code from my _Add.cshtml:

@model MyStore.Models.MyModels.ProductsModel

@{
    Layout = null;
}

@using (Ajax.BeginForm("_Add", "Products", new AjaxOptions
{
    InsertionMode = InsertionMode.Replace,
    HttpMethod = "POST",
    OnSuccess = "addSuccess"
}, new { @id = "addForm" }))
{
    @Html.ValidationSummary(true)      
    <div id="add-message" class="error invisible"></div>

    <fieldset>
        <legend>Products</legend>

        @Html.HiddenFor(m => Model.ProductCode)

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

        <div class="editor-label">
            @Html.LabelFor(model => model.Price)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Price)
            @Html.ValidationMessageFor(model => model.Price)
        </div>
    </fieldset>
} 

Below is the code from my Controller:

[HttpGet]
public ActionResult _Add(string productCode)
{
    ProductsModel model = newProductsModel();
    model.ProductCode = ProductCode ;
    return PartialView(model);
}

[HttpPost]
public JsonResult _Add(ProductsModel model)
{
    if (ModelState.IsValid)
    {
        ProductsManager prod = new ProductsManager();
        Products pa = new Products();

        pa.ProductCode = model.ProductCode;
        pa.ProductName = model.ProductName;
        pa.Price = model.Price;

        prod.AddProduct(pa);

        return Json(HelperClass.SuccessResponse(pa), JsonRequestBehavior.AllowGet);
    }
    else
    {
        return Json(HelperClass.ErrorResponse("Please review your form"), JsonRequestBehavior.DenyGet);
    }
}

Please note that the _Add.cshtml is a partial view which is being rendered through a Popup.js which I found on the internet. It is rendered through this code:

@Html.ActionLink("[Add Product]", "_Add", new { ProductCode = @ViewData["ProductCode"] }, new { @class = "editLink" })

This works okay. I mean it adds product to my database. But my problem is upon clicking the Proceed button, I get this pop-up download dialog from the page:

Screenshot A

Can somebody please help me with this? I have a hunch it’s because of the HttpMethod i’m using (POST, PUT, GET, DELETE) but i’m not really sure which one is right to use or if it really is the problem in the first place.

Any help would be greatly appreciated!
PS.
Sorry for the long post.


EDIT:

This is the tutorial I followed for this project: http://ricardocovo.com/2012/04/06/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms-razor-version/


EDIT:

Below is the jscript code I am using. It’s basically the same one from the tutorial I followed. I just had to comment out a few lines on the last method.

Also, I am using MVC 4. Hope this helps! Thanks!

var linkObj;
$(function () {
    $(".addLink").button();

    $('#addDialog').dialog({
        autoOpen: false,
        width: 400,
        resizable: false,
        modal: true,
        buttons: {
            "Update": function () {
                $("#add-message").html(''); //make sure there is nothing on the message before we continue                         
                $("#addForm").submit();
            },
            "Cancel": function () {
                $(this).dialog("close");
            }
        }
    });

    $(".addLink").click(function () {
        //change the title of the dialog
        linkObj = $(this);
        var dialogDiv = $('#addDialog');
        var viewUrl = linkObj.attr('href');
        $.get(viewUrl, function (data) {
            dialogDiv.html(data);
            //validation
            var $form = $("#addForm");
            // Unbind existing validation
            $form.unbind();
            $form.data("validator", null);
            // Check document for changes
            //$.validator.unobtrusive.parse(document);
            // Re add validation with changes
            //$form.validate($form.data("unobtrusiveValidation").options);
            //open dialog
            dialogDiv.dialog('open');
        });
        return false;
    });

});


function addSuccess(data) {
    if (data.Success == true) {
        //we update the table's info
        //var parent = linkObj.closest("tr");
        //parent.find(".carName").html(data.Object.Name);
        //parent.find(".carDescription").html(data.Object.Description);
        //now we can close the dialog
        $('#addDialog').dialog('close');
        //twitter type notification
        $('#commonMessage').html("Add Complete");
        $('#commonMessage').delay(400).slideDown(400).delay(3000).slideUp(400);
    }
    else {
        $("#add-message").html(data.ErrorMessage);
        $("#add-message").show();
    }
}

I commented out these two lines:

$.validator.unobtrusive.parse(document);
$form.validate($form.data("unobtrusiveValidation").options);

because not commenting them would give me the error below during runtime:
enter image description here

This leads me to the opinion that this issue is due to the unobtrusive validation. Like the link posted by Xnake below, I am having the same kind of problem. The only different thing is that the Thread Opener had to disable unobtrusive validation on his Web.config file to fix the problem whereas I cannot do the same since my code is using unobtrusive validation.

Any help is greatly appreciated here. Thank you very much!

  • 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-07T17:50:19+00:00Added an answer on June 7, 2026 at 5:50 pm

    I already fixed my problem! Apparently, I had to include the following js files on my MasterPage. Hope this helps!

    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a ASP.NET MVC website and I was wandering which techniques do you
I am creating an ASP.Net MVC website that I am launching soon in private
I'm creating a custom MembershipProvider for an ASP.NET MVC website, and I was planning
I've just started creating my first MVC website; what's the best practice to prevent
I'm creating a website using MVC framework (Yii) and I need to dynamically create
I am in the process of creating a website using ASP.NET MVC. I went
I am Creating a new ASP.Net website not mvc, and willing to make the
I'm creating an MVC website and also intend to create a web API for
I am creating an ASP.NET MVC 3 e-commerce website and I am currently working
I'm creating my first ASP.NET MVC 3 website for my company's intranet. It's a

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.