MVC :: JsonResult Only Returns IEnumerable Data?

Mar 31, 2010 06:19 PM

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 = {



Display Data From A Method That Returns An IEnumerable Interface?

Jul 06, 2009 03:00 AM

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 View Related

MVC :: Can JsonResult Method Return Data Table

Jan 16, 2011 01:39 AM

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 View Related

Show Data In A View By Passing A JsonResult?

Apr 27 10 at 14:00

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

View 1 Replies View Related

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

Oct 09, 2010 09:28 PM

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 View Related

C# - Getting Two Different Data Types From IEnumerable?

Jun 29 10 at 13:55

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 View Related

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

Nov 07, 2008 10:47 AM

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 View Related

Forms Data Controls :: Bind Dropdownlist With IEnumerable?

Nov 20, 2010 08:22 AM

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

View 1 Replies View Related

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

Mar 31 10 at 2:12

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 View Related

Use AuthorizeAttribute And JsonResult Together?

Jan 28 at 6:35

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 View Related

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

Mar 14, 2010 03:53 PM

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 View Related

Json - Get The JsonResult In Function?

Jan 31 at 19:58

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 View Related

MVC :: JsonResult And Extjs JsonStore?

Jun 04, 2009 08:23 PM

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 View Related

MVC :: Read Raw Jsonresult Output?

Sep 05, 2010 12:57 PM

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 View Related

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

Nov 19, 2010 08:15 PM

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 View Related

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

Aug 20, 2008 01:00 PM

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 View Related

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

Nov 18, 2009 11:42 PM

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 View Related

Convert A JSON String Into JsonResult?

Apr 21 10 at 17:29

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 View Related

MVC :: Utilize Dynamic Type With JsonResult?

Apr 01, 2011 03:27 AM

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


View 8 Replies View Related

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

Nov 09, 2010 05:01 AM

I created one stored procedure.

SP Name :sp_Par_SearchCourseFinder
Author :Mr.Ravichandran


View 1 Replies View Related

JsonResult Shows Up A File Download In Browser?

Apr 3 10 at 15:22

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 View Related

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

Mar 28, 2010 07:55 PM

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 View Related

MVC :: Internal Server Error On JsonResult Return?

Mar 05, 2010 12:29 PM

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 View Related

Jquery - MVC2 JsonResult This Request Has Been Blocked?

Dec 17 10 at 2:00

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 View Related

C# - Retrieving Selected Item Text Within A JsonResult Function

Mar 3 at 15:33

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 View Related

How To Use IEnumerable Interface

Jun 09, 2010 07:37 AM

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

View 1 Replies View Related

How To Return A IEnumerable

Nov 03, 2008 05:20 PM

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 View Related

Use Of IEnumerator And IEnumerable

Mar 14, 2010 08:13 AM

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

View 3 Replies View Related

ADO.NET :: How To Read IEnumerable

Mar 06, 2011 02:55 PM

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 View Related

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

Feb 27, 2011 02:56 PM

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 View Related

Forms Data Controls :: How To Display Gridview Header And Footer When Sqldatasource Returns No Data

May 13, 2008 10:00 PM

I am using sqldatasource to populate my GridView which contains a header and a footer. I use the footer to inser a new row in the database. The problem is: when the sqldatasource returns with no data in the database, the GridView is not displayed. Therefore, I have no way of inserting a new record under this condition.

how do I keep displaying the GridView with the header and footer even when the sqldatasource returns with no data?

View 4 Replies View Related

Forms Data Controls :: Show Column Headers When Gridview Returns Empty Data Set?

Oct 15, 2010 04:02 PM

I have in my code a gridview that I redirect to excel, it works fine when I have data in the data set. waht I want is to show column headers when there is no data right now what i get is empty sheet.

View 7 Replies View Related

How To Convert List Into Ienumerable

May 01, 2010 12:33 PM

I am using LINQ for data connectivity and have made class which return me the result set into presentation here is the syntax:-

public List<ClsDermaInvestigation> MthdisplayInvestigation()
List<ClsDermaInvestigation> lstinvst = new List<ClsDermaInvestigation>();
ISingleResult<USP_Patient_Dermatology_InvestigationResult> investresult = objderma.USP_Patient_Dermatology_Investigation(PatientID, RepDate, Hb, TLC, F);
foreach(USP_Patient_Dermatology_InvestigationResult rel in investresult)
ClsDermaInvestigation objinvest = new ClsDermaInvestigation();
objinvest.Albumin = Convert.ToDouble(rel.Albumin);
objinvest.ALP = rel.ALP;
objinvest.ANA = rel.ANA;
objinvest.Date =;
lstinvest.add(objinvest)}return lstinvest}
This list is returning me the result.It works fine but in 1 case am using the same list to bind my Date dropdownlist.
//aspx.cs code
List<Dermatology.ClsDermaInvestigation> objlstinvest = objinvest.MthdisplayInvestigation();
//Array s =
drpDate.DataSource = s;
drpDate.DataTextField = "Repdate";
drpDate.DataValueField = "Repdate";

But it throws an error that list does not conatin a property with "Repdate";. How can i bind this list with dropdownlist?? Can i convert it into some type so that i would be able to bind it??

View 2 Replies View Related

ADO.NET :: LINQ And Cast Row To IEnumerable?

Apr 01, 2011 01:13 PM

table1 row = _db.table1.FirstOrDefault(r => r.ReferenceID == refNumber);

Is there anyway to cast row to IEnumerable?

((IEnumerable<table1>)row) - does not work

View 1 Replies View Related

MVC :: Updating Model With IEnumerable?

Apr 19, 2010 08:25 PM

I'm trying to update values I have stored in an IEnumerable using UpdateModel, but it isn't reflecting the changes when I step over it in Debug.I also tried upating it using a foreach loop and updating the values in each object T within the IEnumerable<T>. The values are changed at the object level, but it seems that the value of the object in the IEnumerable isn't being changed.I was looking at IEnumerable<T> and didn't see a way to update it... I'm thinking that I might have to assign the updates to some other data structure, then convert it to an IEnumerable or something before I try to save my repository

View 6 Replies View Related

What Is The Difference Between IEnumerable And List

May 18, 2010 04:57 PM

I've read some articles about this but for some reason they're just not doing it for me. I'd like to understand the difference between

IEnumerable<string> myList and List<string>myListToo

View 7 Replies View Related

It Must Be Either An IListSource, IEnumerable, Or IDataSource?

Feb 24, 2009 01:02 AM

New to Using VWD 2008 express& Sql Server 2005 express. Try the tutorials of data access. Implementing the BLL class, but

ShopBLL shopbll=new ShopBLL();
GridView1.DataSource = shopbll.GetAllShop();

SQL: select * from shops where shopname<>'hot'

View 2 Replies View Related

Retain IEnumerable<T> Value During Postback?

Mar 17 10 at 9:39

I have an IEnumerable< T> which is declared on the page like this:IEnumerable< Person> person;When the page postsback, the person list is null. How can I retain the values of person list without declaring it as static? Sr. devs in my company say that you should not declare the list as static.

View 2 Replies View Related

Convert Datatable To IENumerable?

Feb 10, 2010 06:26 PM

Dim list As List(Of DataRow) = dt.AsEnumerable().ToList()When I compile I get the error:
'AsEnumerable' is not a member of 'System.Data.DataTable'.I added Imports to the file..This code works when I run it on a project But when I use the same code in Website it returns the above error..Can anyone help solve this error.

View 2 Replies View Related

What's All Datasources Implement IEnumerable Interface

Nov 14, 2008 03:00 PM

I wanted to know what all datasouces implement IEnumerable interface.

View 3 Replies View Related

Copyrights 2005-14, All rights reserved