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

The Archive Base Latest Questions

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

I have a view that I pass a viewmodel object to that contains an

  • 0

I have a view that I pass a viewmodel object to that contains an IQueryable<> object.

This object is used to populate an mvccontrib grid. The view also contains other partial views that allow the user to filter the data within the grid.

Once the grid is filtered I would like the user to be able to export the Iqueryable object to another controller actionresult method which then calls another viewmodel that exports the data to Excel.

Here is the snippet of the view that calls the Export actionresult() method:

@using (Html.BeginForm("Export", "Home", FormMethod.Post, new { Model }))
{
  <p>
   <input class="button" value="Export to Excel" type="submit" />
  </p>

}

Model does contain the IQueryable object.

When I debug the code I can view the viewmodel object, and of course in order to populate the IQueryable I must enumerate the object.

I have also created another viewmodel object that, once the Model object is passed back to the actionresult method attempts to enumerate the IQueryable object by either using the .ToList() method or the AsEnumerable() method.

But in all cases the IQueryable object is pass to the controller as a null object.

Here is the action result method that is being called from the view:

[HttpPost]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Export(PagedViewModel<NPSProcessed> NPSData)
{
    string message = "";
    NPSData Query = new Models.NPSData(NPSData);

    Query.IData = NPSData.Query.ToList();

        // Opening the Excel template...
        FileStream fs =
        new FileStream(Server.MapPath(@"\Content\NPSProcessedTemplate.xls"),         FileMode.Open, FileAccess.Read);

        MemoryStream ms = new MemoryStream();

        ee.ExportData(fs, ms, Query.IData, message);

        // Sending the server processed data back to the user computer...
        return File(ms.ToArray(), "application/vnd.ms-excel", "NPSProcessedNewFile.xls"); 

    }

Any assistance would be greatly appreciated.

Thanks

Joe

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

    You cannot pass complex objects around like this: new { Model }. It would have been to easy :-). You will have to send them one by one:

    new { prop1 = Model.Prop1, prop2 = Model.Prop2, ... }
    

    Obviously this could get quite painful. So what I would recommend you is to send only an id:

    new { id = Model.id }
    

    and then inside your controller action that is supposed to export to Excel use this id to fetch the object from wherever you fetched it initially in the GET action (presumably a database or something). If you want to preserve the paging, and stuff that the user could have performed on the grid, you could send them as well to the server:

    new { id = Model.id, page = Model.CurrentPage, sortColumn = Model.SortBy }
    

    Another possibility (which I don’t recommend) consists into saving this object into the session so that you can fetch it back later.

    Yet another possibility (which I still don’t recommend) is to use the MVCContrib’s Html.Serialize helper which allows you to serialize an entire object graph into a hidden field and it will be sent to the server when the form is submitted and you will be able to fetch it as action argument.

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

Sidebar

Related Questions

I have a view that contains two NSTextFieldCell s. The size at which these
In my viewmodel, I have a list (ObservableCollection) containing items. In the view, this
OK so I have a strongly-typed Customer Details view that takes a Customer object
I have a view that will look like this: I'm trying to figure out
I am getting this error when trying to pass my object to the view.
I have a view that has a list of jobs in it, with data
I have a view that I want to add some custom drawing to. I
I have a View that can vary significantly, depending on the 'mode' a particular
I have a view that is joining two tables and ordering by the first
I have a view that is loaded in the MainWindow.xib. It is just 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.