MVC :: JsonResult Only Returns IEnumerable Data?

Mar 31, 2010

My controller has a member that returns a JsonResult object, it is coded as per below. The problem is that Json(users) only returns the data from IEnumerable (MembershipUserEx objects) and I also want the data from the public Properties of MembershipUserExCollection as well. Is there a way to do this? I guess I am looking for the Json object to look something like this pseudo object:

results = {


View 1 Replies

Similar Messages:

Display Data From A Method That Returns An IEnumerable Interface?

Jul 6, 2009

I've been trying to get a handle on the IEnumerable<T> interface and how to display data from a method that returns an IEnumerable<T> interface. Specifically, I'm trying an example that gets data thru the google analytics api using a .net reader. The example method returns a IEnumberable<T> interface:


Here is the class used as the type above:


So, I'm just trying to use the example method to request a CityReport and display the data on a webpage. I've successfully authenticated, called the GetUserCountByLocation method and assigned to a IEnumberable<CityReport> report variable.


If I just reponse.write the report variable, I get:


How do I display the data to the page?

View 3 Replies

MVC :: Can JsonResult Method Return Data Table

Jan 16, 2011

I am wondering if jsonResult method can be used to return Data Table? If so, is it a json array or a json string?

View 6 Replies

Show Data In A View By Passing A JsonResult?

Apr 27, 2010

How Can we Show Data in a View By passing a jsonResult?

View 1 Replies

MVC :: Using Jsonresult Actions To Pass Json Data To Third Party Apps?

Oct 9, 2010

i want to use MVC 2 actions to pass JSON data to a 3rd party application via a URL.The URL will be in the form of am using JSonResultHow can i test the output of this URL to ensure the JSON is properly formed..

View 2 Replies

C# - Getting Two Different Data Types From IEnumerable?

Jun 29, 2010

I have IEnumerable object with value1 and value2. value2 is an array and value1 is string. I want to databind this object to Listview like that. So both value1 and value2[0] (always first item in array) could be accessed via <%# Eval("value1") %> and <%# Eval("value2") %> .

How to write expression to handle both items ?

ListViewItems.DataSource = f.Items.Select(t => t.value1, t.value2[0]);

View 1 Replies

DataSource Controls :: The Data Source 'ObjectDataSource1' Does Not Support Sorting With IEnumerable Data

Nov 7, 2008

I have a BLL and DAL with Custom Objects which I'm trying to display in a grid.

I can use an ObjectDataSource with a Select Method "GetAllUsers()" say, which returns a list of Users. This displays fine in the grid, but when I try and sort it I get the following error:

"The data source 'ObjectDataSource1' does not support sorting with IEnumerable data. Automatic sorting is only supported with DataView, DataTable, and DataSet. "

I did some digging around and I understand that I can either implement some further methods/properties in my Objects to allow them to be sortable, or I can flatten my list of objects into a DataTable. I thought this might be an easier option and found some code to do it.

This method serializes an object and returns its associated DataTable:


It works great except the DataTypes don't appear to be retained. I have a Date Field which I can't format in my grid and I think its because its been flattened into a string.

View 4 Replies

Forms Data Controls :: Bind Dropdownlist With IEnumerable?

Nov 20, 2010

question is same as in thread, but also i would like to see example of this.

View 1 Replies

C# - Enable Automatic Sorting Of IEnumerable Data In GridView?

Mar 31, 2010

How can I enable automatic sorting of my BLL which returns a list, CustomerList:List in a GridView? Customer is my own strongly typed class and CustomerList is a List of customers.I know one approach is to set the AllowSorting property to true in the GridView and handle the OnSorting event and calling a sorting method defined in my CustomerList class.

However I would like a solution which is automatic in the sense that I do not have to handle the OnSorting Event, it should be like how GridView handles automatic sorting for DataView, DataTable, and DataSet.Is there an Interface I need to implement on my CustomerList or Customer class that will enable that functionality?

View 2 Replies

Use AuthorizeAttribute And JsonResult Together?

Jan 28, 2011

What is the most straight forward way to use AuthorizeAttribute and JsonResult together so that when the user is not authorized the application returns a Json error rather than a log in page?The two things I am currently considering are extending AuthorizeAttribute or just making a new attribute that implements IAuthorizationFilter.

View 1 Replies

Forms Data Controls :: Datatable To Ienumerable - Not Getting Results In The Gridview

Mar 14, 2010

I have a dataset that has two datatables. In the first datatable I have EmpNo,EmpName and EmpAddress. In the second datatable I have Empno,EmpJoindate, EmpSalary. I want a result where I should show EmpName as the label and his/her details in the gridview. I populate a datalist with the first table, and have EmpNo as the datakeys. Then I populate the gridview inside the datatable which has EmpNo,EmpJoinDate and EmpAddress. My code is


My Design is

<asp:DataList ID="Datalist1" runat="server" DataKeyField="EmpNo">
<asp:GridView ID="Gridview1" runat="server">

I do not get results in the gridview, instead have errors. I tried then placing the bound field

<asp:GridView ID="Gridview1" AutoGenerateColumns="true" runat="server">
<asp:BoundField DataField="EmpNo" />

It throwed an error stating / A field or property with the name 'EmpNo' was not found on the selected data source.

View 3 Replies

Json - Get The JsonResult In Function?

Jan 31, 2011

How can I get the result of a method that return a JsonResult and cast into string.

public JsonResult AnalyseNbPayment(DateTime dt, DateTime dt2,int FrequencyID) {
if (FrequencyID == ApplConfig.Frequency.WEEKLY) {
return Json(new { val = GetNbWeek(dt, dt2) });
else if (FrequencyID == ApplConfig.Frequency.MONTHLY) {
return Json(new { val =GetDateDiffInMonth(dt, dt2) });
else if (FrequencyID == ApplConfig.Frequency.QUARTELY) {
return Json(new { val = GetQuarterLy(dt, dt2) });
else if (FrequencyID == ApplConfig.Frequency.BI_MONTLY) {
return Json(new { val = GetBiMontlhy(dt, dt2) });
else if(FrequencyID == ApplConfig.Frequency.YEARLY)
return Json(new { val = GetNbYear(dt, dt2) });
return Json(new { val =0 });

I want to call my method like this

string MyValue = AnalyseNbPayment(Convert.ToDateTime(ViewModel.oRent.DateFrom), Convert.ToDateTime(ViewModel.oRent.DateTo), Convert.ToInt32(oLease.FrequencyID)).val.ToString(); <br />

View 1 Replies

MVC :: JsonResult And Extjs JsonStore?

Jun 4, 2009

I am trying to use the JsonResult to populate a extjs grid using the extjs JsonStore. The JsonStore requires the json to be formatted in a specific way which I have been unable to make happen. The JsonStore requires the json to be formatted like this.


I'm using a linq to sql query to get the data and then I'm passing the linq variable to the Controller.Json method as the return type. What this gives me is the following.

[{"Code":0,"Label":"Not Processed"},{"Code":1,"Label":"Wish List"},{"Code":2,"Label":"Review Soon"},{"Code":3,"Label":"Subsequent Release"},{"Code":4,"Label":"Scheduled for Release"},{"Code":5,"Label":"Immediate Build/Patch"},{"Code":8,"Label":"Refused"},{"Code":9,"Label":"Non-Problem"}]

I'm missing the results: and rows: properties. The only way I can think of to add the results: and rows: properties is to serialize the linq variable to create a string and then manually add the properties to the string. This I think is creating two new problems. One is that I then pass the json string to the Controller.Json method and the json string is getting serialized a second time which causes the returned json to have a bunch of back slashes, one before each double qoute. The second problem is that when I manually add the two properties they get stripped off in the Controller.Json method. Why Json method stripping off the properties?Here is the link to my forum post on the extjs website. I also just started this thread.

View 5 Replies

MVC :: Read Raw Jsonresult Output?

Sep 5, 2010

How can i get to see the raw jsonresult of an action in a controller? i want to make sure its returning correctly formed data.

View 4 Replies

Forms Data Controls :: How To Accept An 'object' As A Datasource (IEnumerable Or IList)

Nov 19, 2010

How do I accept an 'object' as a Datasource (IEnumerable or IList) and loop through the keys/values? I want to be able to pass anything that implements either IEnumerable or IList.

This same functionality exists on all of the .Net DataBound controls and I'm trying to figure out how it's done.


View 6 Replies

Forms Data Controls :: Paging Gridview With IEnumerable Object As Datasource

Aug 20, 2008

I have a gridview that is bound to a custom object that implements IEnumerable. For reasons that I won't go into here, I have to get all the rows at once, ie I don't get one page at a time. Since I have to get all the rows up front it would seem inefficient to go and get the data again a page at a time just to implement paging. Is there a way to set the grid to page the data without a custom paging routine? If I simply set the gridview to Paging enabled I get an error saying the datasource does not support server-side paging. Isn't there a way to give the gridview all the data and have it just display the pages like in "the old days"?

View 5 Replies

Forms Data Controls :: ListBox DataBind On IEnumerable Looses All Items?

Nov 18, 2009

I have two listboxes with an add/remove scenario. The first one gets populated with all the items and the second one contains the items which the user is intersted in. In order to achieve this I have an add button and remove button.

1. When the user clicks the add button the items selected in the first listbox are added to the second list box. I use LINQ to figure out the items selected and I do a databind on the second list box with type IEnumerable<ListItem>. Given below is a sample code.

IEnumerable<ListItem> selectedItems = from itm in lstAvailableStocks.Items.Cast<ListItem>()
where itm.Selected
select itm;

I do a data bind on selectedItems. This works fine as expected.

2. The problem is when the user clicks the remove button by selecting specific items from the second list box. When this happens again I do a select using LINQ on the second list box and do a databind. Given below is the LINQ statement

IEnumerable<ListItem> selectedStocks = from itm in lstSelectedStocks.Items.Cast<ListItem>()
where !itm.Selected
select itm;

Now if I do a count on selectedStocks and examine the items I get the proper values. However as soon as I do a .DataSource = selectedStocks and then a DataBind() all the items in selectedStocks suddenly vanish and the list box to which this was bound shows nothing.

View 1 Replies

Convert A JSON String Into JsonResult?

Apr 21, 2010

I have some stored JSON strings stored in the DB which I want to return to the client as JsonResult . I know that Json(object) turns an object into JsonResult but what if I already have the result in a string ? can I cast it to JsonResult

View 2 Replies

MVC :: Utilize Dynamic Type With JsonResult?

Apr 1, 2011

Is it possible to do something like this inside an action?


View 8 Replies

DataSource Controls :: Data Source Is An Invalid Type Must Be Either An IListSource, IEnumerable, Or IDataSource?

Nov 9, 2010

I created one stored procedure.

SP Name :sp_Par_SearchCourseFinder
Author :Mr.Ravichandran


View 1 Replies

JsonResult Shows Up A File Download In Browser?

Apr 3, 2010

I'm trying to use jquery.Ajax to post data to an ASP.NET MVC2 action method that returns a JsonResult. Everything works great except when the response gets back to the browser it is treated as a file download instead of being passed into the success handler. Here's my code:



If I open the downloaded file the json is exactly what I'm looking for and the mime type is shown as application/json. What am I missing to make the jquery.ajax call receive the json returned?

View 3 Replies

MVC :: RenderPartial To String For JsonResult While Maintaining Testability?

Mar 28, 2010

I would like to wrap a RenderPartial in a JsonResult so that my jQuery can handle placement/positioning of the html data based on additional Json parameters.

e.g. {html: <string returned from RenderPartial>, typeofdata: 1}

After Googling, it seems that the only way to do this is a workaround that hijacks HttpContext in order to spit the PartialViewResult into a string. However, this seems like it would break testability.

Is JsonResult not intended to be used with RenderPartial?

Alternatively, I could set typeofdata as a parameter of the model, and have the PartialView render it as a hidden field, then have jQuery look for it. What is a better way to generate the data that I need?

View 5 Replies

MVC :: Internal Server Error On JsonResult Return?

Mar 5, 2010

I've got an ActionMethod that returns a JsonResult object and this isn't returning data to the calling jquery function. I have used wget to send and receive raw data to it, and I've discovered that when the object dataset is empty, it returns a value fine and the wget return is

HTTP request sent, awaiting response... 200 OK

Length: 78 [application/json]

Saving to: `filename'

but when there is data in the object dataset I get an internal server error:-

HTTP request sent, awaiting response... 500 Internal Server Error

2010-03-05 13:21:16 ERROR 500: Internal Server Error.

This is a dataset of objects being returned - are there any common "gotchas" when doing this?

View 8 Replies

Jquery - MVC2 JsonResult This Request Has Been Blocked?

Dec 17, 2010

I know the question is very familiar but i can't over it.This is my Controller Action

public JsonResult AddToCart(int productId, int quantity = 1, int optionValue = 0)
AjaxActionResponse res = new AjaxActionResponse();


View 2 Replies

C# - Retrieving Selected Item Text Within A JsonResult Function

Mar 3, 2011

I am creating an MVC project with a table using the JQGrid plugin. I would like to use a DropDownList to allow the user to specify a value, that will be used in an SQL query to retrieve specific data from the table. I.e. user can select a country from the list, and the table will display items only from that country. I cannot figure out how to retrieve the selected item from the DropDownList, within my data bind function for my table, within my controller class.

DropDownList in the View

<%= Html.DropDownList("Countries")%>

Setting up the DropdownList in my controller

//dt is a DataTable which holds the values for my list
List<SelectListItem> countries = new List<SelectListItem>();
for (int i = 0; i < dt.Rows.Count; i++)
The problem seems to be that within a JsonResult function I don't have access to the ViewData or my ViewModel, which always seem to be null when I try and access them. I am very new to MVC and web development,

View 2 Replies

How To Use IEnumerable Interface

Jun 9, 2010

i was looking at one example on msdn [URL], but i can't really understand it.

View 1 Replies

How To Return A IEnumerable

Nov 3, 2008

static System.Collections.Generic.IEnumerable<string>
string[] specificCausesOfDeath =
//Name of Stored Procedure.
string sqlCommand =
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
//Invoke a SQL command.
using (IDataReader dataReader =
while (dataReader !=
null && dataReader.Read())

If I am on the right track what code do I need to put here to read the data out of the dataReader and add it to the string[]

//Return an IEnumerable string.
return specificCausesOfDeath;

View 1 Replies

Use Of IEnumerator And IEnumerable

Mar 14, 2010

refer me few article which describe the basic use of IEnumerator and IEnumerable,

View 3 Replies

ADO.NET :: How To Read IEnumerable

Mar 6, 2011

I have function it will return IEnumerable as.

IEM = myclass.getdata("name");

How to read the data in IEM as it consists of many columns. I have to display the values into labels and textboxes.

View 3 Replies

Forms Data Controls :: GridView Page Returns Data From The Previous?

Feb 27, 2011

I am using a Gridview binded to a LinqDataSource that represents a database view. The gridview paging is enabled. When navigating from page 1 to page 2, it displays the right count of rows in this page (assume pagesize is 10 and page 2 should have 4 rows only to have total of 14 rows in the view; the datasource), however, it populates wrong data (from the previous page). On the contrary, when I disable paging, everything works ok.


View 6 Replies

Copyrights 2005-15, All rights reserved