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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:00:23+00:00 2026-05-25T19:00:23+00:00

I’m working on my first ASP.NET MVC 3 application and what I want to

  • 0

I’m working on my first ASP.NET MVC 3 application and what I want to accomplish is that a user can select a recipe from my grid and then have it displayed in a div called details. There the user can click the Edit button and the view switches to an edit view within that same div and then when the user has made changes the Save button can be clicked which would persist the changes and redisplay the details.

I’m using jqGrid (not really germane to the discussion) and have a bit of code to populate the details div like so:

onSelectRow: function(theRow) {
   var grid = jQuery('#recipeGrid');
   var cellData = grid.jqGrid('getCell', theRow, 'RecipeID');
   $('#details').load('@Url.Action("Details", "Recipe")', { id: cellData });
}

In that details view there’s a button and some jQuery which does a similar thing to swap out this details view with a details edit:

<input type="button" value="Edit" class='editrecipe' data-recipeid="@Model.RecipeID" />

<script type="text/javascript" language="javascript">
   $(function () {
      $('.editrecipe').click(function () ){
         var recipeId = $(this).data('reciepid');
         $.ajax({
            type: "GET",
            data: "id=" + recipeId,
            url: '@Url.Action("Edit", "Recipe")',
            dataType: "html",
            success: function (result) {
               $('#details').html(result);
            }
         });
      });
   });
</script>

Then on that edit looks something like this:

@model IceCream.ViewModels.Recipe.RecipeCreateEditViewModel
@using (Html.BeginForm())
{
   ...
   <input type="button" value="Save" class='saverecipe' />
}

<script type="text/javascript" language="javascript">
   $(function () {
      $('.saverecipe').click(function () ){
         $.ajax({
            type: "POST",
            data: $('form').serialize(),
            cache: false,
            url: '@Url.Action("Edit", "Recipe")',
            dataType: "html",
            success: function (result) {
               $('#details').html(result);
            }
         });
      });
   });
</script>

Back in my controller action, I noticed that some of the properties of the viewModel are correct but most are null. I’m guessing that I’m doing something wrong here related to the ajax call where the serialization happens (or doesn’t). Any ideas?


Update:

So, I changed a few things and it looks better. First, I gave my form an ID like so:

@using (Html.BeginForm("Edit", "Recipe", FormMethod.Post, new { id = "editRecipeForm" }))

Then I altered my Save button to look like so:

<input type="submit" value="Save" />

Then the jQuery looks like this:

$('#editRecipeForm').submit(function () {
   var options = {success: function (html) {
      $("#details").replaceWith($('#details', $(html)));
   },
   url: '@Url.Action("Edit", "Recipe")'
   }
   $(this).ajaxSubmit(options);
   return false;
});

At least initially, it looks like my viewModel is now being populated correctly in the POST action. However it does NOT seem to execute the success callback. What I do in my controller action is call

return Details(viewModel.RecipeID);

which I expect will return the PartialView back and the success callback would replace the contents of the ‘#details’ div with that info. What actually happens is that it just returns the Details and displays that – not in the div. Ideas?


A Solution:

Until I went in and created a bad Action in the url: '@Url.Action("Edit", "Recipe")' line, I was fooling myself that this was actually running. Reason? Didn’t have jquery.form.js included… that’ll help things. :-p

I modified things a bit. Looks like this now:

var options = {
   target: "#details",
   url: '@Url.Action("Edit", "Recipe")',
};

and then

$('#editrecipeform').submit(function () {
   $(this).ajaxSubmit(options);
   return false;
});

Still would be interested in the thoughts of others on this – particularly if there is a better way to do this.

  • 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-25T19:00:24+00:00Added an answer on May 25, 2026 at 7:00 pm

    Instead of:

    $('#editrecipeform').submit(function () {
       $(this).ajaxSubmit(options);
       return false;
    });
    

    I’d use:

    $(function() {
        $('#editrecipeform').ajaxForm(options);
    });
    

    Other than this small remark your solution with the jquery.form plugin is really nice.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.