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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:37:29+00:00 2026-05-17T22:37:29+00:00

I am trying to figure out how to pass the model object from controller

  • 0

I am trying to figure out how to pass the model object from controller to view in a following scenario:

<% Html.Action("GetRequest", "The_Controller", new { requestId = 12 }); %>
<% Html.RenderPartial("Request", ViewData.Model); %>

The action should, and it does, call the controller’s method which looks up the Request object in the DB repository and returns a Request object.

The partial view, named Request, should receive the request object and display it.

The problem is that the ViewData.Model is always null?!

I have tried to figure it out, but with no success 🙁

The reason for this behavior is that I need to display a partial view inside the jQuery’s modal dialog based on the requestId value provided by the jQGrid. I have reached the point where I open the dialog but can’t get that model object instance.

Any help is appreciated.

The solution – With the help of Nick Larsen and Darin Dimitrov

The controller:

    [AcceptVerbs(HttpVerbs.Post)]
    [Authorize]
    public PartialViewResult GetRequest(string requestId)
    {
        Request request = DatabaseContext.GetRequest(Convert.ToInt32(requestId)) as Request;
        return PartialView("Request", request);
    }

The view’s Javascript:

function OpenRequest(requestId) {

        var methodName = '<%= Url.Content("~")%>' + 'Controller/GetRequest/';
        var dataType = "html";
        var postData = { requestId: requestId };
        var contentType = "application/x-www-form-urlencoded"; ;
        var request = ContactServer(methodName, postData, dataType, contentType);

        $("#dialog").html(request);
        $("#dialog").dialog({ html: request, title: 'Request details...', width: 800, height: 600, modal: true, zindex: 300000, show: 'scale', resizable: false });

    }
  • 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-17T22:37:29+00:00Added an answer on May 17, 2026 at 10:37 pm

    It’s better to set it up where your view does not call your controller. Load all of the data for the request in the action which calls this view and populate a view model with the needed data. Once you have that, render the fields from the model.

    As for your actual problem. The action that calls this view in the first place populates the ViewData.Model for its context. When you call the action method, the framework is creating a new context with its own ViewData which you dont have access to without a handle to that newly created context.

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

Sidebar

Related Questions

I'm trying to figure out a way to pass the entire class from my
Trying to figure out a way where I can pass some data/fields from a
I'm trying to figure out how to pass a model across views Here is
I am trying to figure out how to pass a UIImage around between various
I was trying to figure out if it was possible to pass in a
I'm trying to figure out the best way to load a textured 3D model
I am trying to figure out how to pass two different parameters of the
I'm trying to figure out how to pass an argument to one function, which
Hey i'm trying to figure out Function pointers and how to pass them around/
I'm trying to figure out how to pass arguments to an anonymous function in

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.