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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:42:01+00:00 2026-05-25T23:42:01+00:00

I have an action (Index) that return a View with a concrete model. Inside

  • 0

I have an action (Index) that return a View with a concrete model.

Inside that view (Is a calendar) I have two buttons to change months.

When I click one of those I call back Index action to that will return the same view with a modified model.

$("#right").live("click", function () {
    $.post($(this).attr("href"), function (response) {
        $("#wrapper").replaceWith($(response).filter("div#wrapper"));
    });
    return false;
});

So, I click #right and it call /Home/Index and Index return something like:

return View(new DateViewModel(dt, _bDays.GetDaysFromMonth(dt)));

So as you see, I replace div#wrapper with the new one. Perfect but…

Is there a way to get the model of the response? I mean, that action return a view with a model and apart from getting the concrete div I want the model.

Any idea?

  • 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-25T23:42:02+00:00Added an answer on May 25, 2026 at 11:42 pm

    I don’t know why you would need the model in the AJAX callback, and thus there is probably a better solution than the one I am about to propose. So you could have your controller action render the partial view into a string and then return a JSON object containing both the HTML and the model:

    [HttpPost]
    public ActionResult MyAction()
    {
        MyViewModel model = new DateViewModel(dt, _bDays.GetDaysFromMonth(dt));
        string html = RenderPartialToString("partialName", model);
        return Json(new { Model = model, Html = html });
    }
    

    and in your AJAX callback:

    $.post($(this).attr("href"), function (response) {
        var model = response.Model;
        var html = response.Html;
        $("#wrapper").replaceWith($(html).filter("div#wrapper"));
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a controller action that returns a simple view return View(Index); Is
I have code that looks like the following: <form id=MyForm name=MyForm method=post action=index.php> <input
I have a controller method that looks like this: [AcceptGet] public ActionResult Index(SecurityMatrixIndexViewModel model)
Let's say I have a ColorsController and a Colors/Index.cshtml View for that controller. I
On ASP.NET MVC 3, assume that we have following controller action: public ActionResult Index()
I'm using MVC3 and in my view I have the following code block; Response.Redirect(@Url.Action(index,home,
I have a Action that sends a simple email: [HttpPost, ActionName(Index)] public ActionResult IndexPost(ContactForm
I have the following index action: class ExpensesController < ApplicationController def index() @expenses =
I have a post html form, and the action is index.php, which is the
I have a controller named Content, which has an Index action, which is associated

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.