Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    ASP.NET


Advertisements:










MVC :: JsonResult Only Returns IEnumerable Data?


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 = {
pageIndex:0,
pageSize:50,

[code]...


View 1 Replies (Posted: Mar 31, 2010 06:19 PM)

Sponsored Links:

Related Forum Messages For ASP.NET category:
Display Data From A Method That Returns An IEnumerable Interface?
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 examplethat getsdata thru the google analytics api using a .net reader. The example method returns a IEnumberable<T> interface:

[Code]....

Here isthe class used as the type above:

[Code]....

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

[Code]....

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

System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,GoogleAnalytics.Reports.CityReport]

How do I display the data to the page?

Posted: Jul 06, 2009 03:00 AM

View 3 Replies!   View Related
MVC :: Can JsonResult Method Return Data Table
I am wondering if jsonResult method can be used to return Data Table? If so, is it a json array or a json string?

Posted: Jan 16, 2011 01:39 AM

View 6 Replies!   View Related
Show Data In A View By Passing A JsonResult?
How Can we Show Data in a View By passing a jsonResult?

Posted: Apr 27 10 at 14:00

View 1 Replies!   View Related
MVC :: Using Jsonresult Actions To Pass Json Data To Third Party Apps?
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 http://www.abc.com/controller/action..I am using JSonResultHow can i test the output of this URL to ensure the JSON is properly formed..

Posted: Oct 09, 2010 09:28 PM

View 2 Replies!   View Related
C# - Getting Two Different Data Types From IEnumerable?
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]);
ListViewItems.DataBind();

Posted: Jun 29 10 at 13:55

View 1 Replies!   View Related
DataSource Controls :: The Data Source 'ObjectDataSource1' Does Not Support Sorting With IEnumerable Data
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:

[code]...

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.

Posted: Nov 07, 2008 10:47 AM

View 4 Replies!   View Related
Forms Data Controls :: Bind Dropdownlist With IEnumerable?
question is same as in thread, but also i would like to see example of this.

Posted: Nov 20, 2010 08:22 AM

View 1 Replies!   View Related
C# - Enable Automatic Sorting Of IEnumerable Data In GridView?
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?

Posted: Mar 31 10 at 2:12

View 2 Replies!   View Related
Use AuthorizeAttribute And JsonResult Together?
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.

Posted: Jan 28 at 6:35

View 1 Replies!   View Related
Forms Data Controls :: Datatable To Ienumerable - Not Getting Results In The Gridview
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

[Code]....

My Design is

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

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">
<Columns>
<asp:BoundField DataField="EmpNo" />
</Columns>

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

Posted: Mar 14, 2010 03:53 PM

View 3 Replies!   View Related
Json - Get The JsonResult In Function?
How can I get the result of a method that return a JsonResult and cast into string.

[HttpPost]
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 />

Posted: Jan 31 at 19:58

View 1 Replies!   View Related
MVC :: JsonResult And Extjs JsonStore?
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.

[Code]....

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. http://extjs.com/forum/showthread.php?t=70373. I also just started this thread. http://extjs.com/forum/showthread.php?t=70391

Posted: Jun 04, 2009 08:23 PM

View 5 Replies!   View Related
MVC :: Read Raw Jsonresult Output?
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.

Posted: Sep 05, 2010 12:57 PM

View 4 Replies!   View Related
Forms Data Controls :: How To Accept An 'object' As A Datasource (IEnumerable Or IList)
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.

[Code]....

Posted: Nov 19, 2010 08:15 PM

View 6 Replies!   View Related
Forms Data Controls :: Paging Gridview With IEnumerable Object As Datasource
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"?

Posted: Aug 20, 2008 01:00 PM

View 5 Replies!   View Related
Forms Data Controls :: ListBox DataBind On IEnumerable Looses All Items?
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.

Posted: Nov 18, 2009 11:42 PM

View 1 Replies!   View Related
Convert A JSON String Into JsonResult?
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

Posted: Apr 21 10 at 17:29

View 2 Replies!   View Related
MVC :: Utilize Dynamic Type With JsonResult?
Is it possible to do something like this inside an action?

[Code]....

Posted: Apr 01, 2011 03:27 AM

View 8 Replies!   View Related
DataSource Controls :: Data Source Is An Invalid Type Must Be Either An IListSource, IEnumerable, Or IDataSource?
I created one stored procedure.

/*
SP Name :sp_Par_SearchCourseFinder
Author :Mr.Ravichandran

[code]...

Posted: Nov 09, 2010 05:01 AM

View 1 Replies!   View Related
JsonResult Shows Up A File Download In Browser?
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:

Javascript:

[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?

Posted: Apr 3 10 at 15:22

View 3 Replies!   View Related
MVC :: RenderPartial To String For JsonResult While Maintaining Testability?
I would like to wrapa RenderPartial in a JsonResultso that my jQuerycan handle placement/positioning of the html data based on additional Json parameters.

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

After Googling, it seems that the only way to do this is a workaround that hijacks HttpContext in order tospit thePartialViewResult 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 ofthe model, and havethe PartialView renderit as a hiddenfield, then have jQuery look for it. What isa better way togenerate the data that I need?

Posted: Mar 28, 2010 07:55 PM

View 5 Replies!   View Related
MVC :: Internal Server Error On JsonResult Return?
I've got an ActionMethod that returns a JsonResult object and this isn't returning data to the callingjquery function. I have usedwget to send and receive raw data to it, and I've discovered that when the object datasetis 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?

Posted: Mar 05, 2010 12:29 PM

View 8 Replies!   View Related
Jquery - MVC2 JsonResult This Request Has Been Blocked?
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();

[code]...

Posted: Dec 17 10 at 2:00

View 2 Replies!   View Related
C# - Retrieving Selected Item Text Within A JsonResult Function
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++)
[code]....
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,

Posted: Mar 3 at 15:33

View 2 Replies!   View Related
How To Use IEnumerable Interface
i was looking at one example on msdn [URL], but i can't really understand it.

Posted: Jun 09, 2010 07:37 AM

View 1 Replies!   View Related
How To Return A IEnumerable
public
static System.Collections.Generic.IEnumerable<string>
GetSpecificCauseofDeath()
{
string[] specificCausesOfDeath =
null;
//Name of Stored Procedure.
string sqlCommand =
"syl_DeceasedInfo_GetSpecificCauseOfDeath";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
//Invoke a SQL command.
using (IDataReader dataReader =
db.ExecuteReader(dbCommand))
{
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;
}

Posted: Nov 03, 2008 05:20 PM

View 1 Replies!   View Related
Use Of IEnumerator And IEnumerable
refer me few article which describe the basic use of IEnumerator and IEnumerable,

Posted: Mar 14, 2010 08:13 AM

View 3 Replies!   View Related
ADO.NET :: How To Read IEnumerable
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.

Posted: Mar 06, 2011 02:55 PM

View 3 Replies!   View Related
Forms Data Controls :: GridView Page Returns Data From The Previous?
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.

[Code]....

Posted: Feb 27, 2011 02:56 PM

View 6 Replies!   View Related
Forms Data Controls :: How To Display Gridview Header And Footer When Sqldatasource Returns No Data
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?

Posted: May 13, 2008 10:00 PM

View 4 Replies!   View Related
Forms Data Controls :: Show Column Headers When Gridview Returns Empty Data Set?
I have in my code a gridview that I redirect to excel, it works fine when I have datain the data set.waht I want is to show column headers when there is no data right now what i get is empty sheet.

Posted: Oct 15, 2010 04:02 PM

View 7 Replies!   View Related
How To Convert List Into Ienumerable
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 = rel.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 = objlstinvest.to
drpDate.DataSource = s;
drpDate.DataTextField = "Repdate";
drpDate.DataValueField = "Repdate";
drpDate.DataBind();

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??

Posted: May 01, 2010 12:33 PM

View 2 Replies!   View Related
ADO.NET :: LINQ And Cast Row To IEnumerable?
table1 row = _db.table1.FirstOrDefault(r => r.ReferenceID == refNumber);

Is there anyway to cast row to IEnumerable?

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

Posted: Apr 01, 2011 01:13 PM

View 1 Replies!   View Related
MVC :: Updating Model With IEnumerable?
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 Twithin 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

Posted: Apr 19, 2010 08:25 PM

View 6 Replies!   View Related
What Is The Difference Between IEnumerable And List
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

Posted: May 18, 2010 04:57 PM

View 7 Replies!   View Related
It Must Be Either An IListSource, IEnumerable, Or IDataSource?
New to ASP.net. 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();
GridView1.DataBind();

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

Posted: Feb 24, 2009 01:02 AM

View 2 Replies!   View Related
Retain IEnumerable<T> Value During Postback?
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.

Posted: Mar 17 10 at 9:39

View 2 Replies!   View Related
Convert Datatable To IENumerable?
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 system.data.datatableextensions to the file..This code works when I run it on a asp.net project But when I use the same code in Website it returns the above error..Can anyone help solve this error.

Posted: Feb 10, 2010 06:26 PM

View 2 Replies!   View Related
What's All Datasources Implement IEnumerable Interface
I wanted to know what all datasouces implement IEnumerable interface.

Posted: Nov 14, 2008 03:00 PM

View 3 Replies!   View Related
Copyright 2005-08 www.BigResource.com, All rights reserved