We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Specified argument was out of the range of valid values.

Hi,
Im in the process of evaluating syncfusion MVC controls for an internal project. The tools you provide look very promising, so I downloaded the trial version to play with it and see how easy to use. The first thing I tried is to create a simple grid, and I just followed the same example you provide in your tutorial, by displaying a simple list of orders that I get from SQL DB. The Code in the View looks like this, and basically Im trying to display one column grid as follows:

<%Html.Grid(

"MvcGridServerMode","GridModel" ,

column =>{

column.Add(p => p.Id);


}); %>

When I run the application. I get the following exception on the code above :
"Specified argument was out of the range of valid values "
Im not sure why.
The code in the controller looks as follows:

public ActionResult Index()
{
ViewData["Message"] = "Welcome to ASP.NET MVC!";

MvcGridModel model = new MvcGridModel()
{
DataSource = Order.GetOrdersList(),
SkinName = "Syncfusion-Grid-Office2007Black",
ActionMode = "Server",
CaptionText = "Orders",
HeaderText = { "Order ID"}

};
ViewData["GridModel"] = model;



return View();
}
Im not sure what the problem is? But I hope you can help me resolve it so I can continue the evaluation.
Thanks



7 Replies

ML Muthukumar L Syncfusion Team May 25, 2009 04:23 AM UTC

Hi Samer,



Thanks for your interest in Syncfusion products.



The DatasourceType has to be mentioned in Grid’s HtmlHelperExtesion Method. Please refer to the following code snippet, in which Datasource type would be your Orders type.



<%Html.Grid(



"MvcGridServerMode","GridModel" ,



column =>{



column.Add(p => p.Id);



}); %>



Regards,

Muthukumar.L


FR Frank Raab June 20, 2009 12:37 AM UTC

I'm having the same problem, and in the reply above I don't see how that code snippet applies, as it is exactly what the original post contained.

I've noticed if I look at model.DataSource, in the sample code the type looks like this:
model.DataSource
{SELECT TOP (20) [t0].[Order ID] AS [OrderID], [t0].[Customer ID] AS [CustomerID], [t0].[Employee ID] AS [EmployeeID], [t0].[Ship Name] AS [ShipName], [t0].[Ship Address] AS [ShipAddress], [t0].[Ship City] AS [ShipCity], [t0].[Ship Region] AS [ShipRegion], [t0].[Ship Postal Code] AS [ShipPostalCode], [t0].[Ship Country] AS [ShipCountry], [t0].[Ship Via] AS [ShipVia], [t0].[Order Date] AS [OrderDate], [t0].[Required Date] AS [RequiredDate], [t0].[Shipped Date] AS [ShippedDate], [t0].[Freight]
FROM [Orders] AS [t0]
}
model.DataSource.GetType()
{Name = "DataQuery`1" FullName = "System.Data.Linq.DataQuery`

When I try using my linq data source, it looks like this:

model.DataSource
{Table(Orders)}
Context: {MyProject.Models.MyDataContext}
IsReadOnly: false

model.DataSource.GetType()
{Name = "Table`1" FullName = "System.Data.Linq.Table`

The one in the sample is a query, when I try it, it's a table.

Frank


FR Frank Raab June 20, 2009 06:18 PM UTC

A followup:

I tried using the JSON example and got the same error. In this case, though, model.DataSource.GetType() returned List of the model object type. What other arguments in this call can produce this error?

I, too, am evaluating your product for an MVC upgrade to a system which deals with 600,000-800,000 users. The features looks great so far, but step one is to get it to work with Linq. The sample code in your CHM file doesn't match the code in your sample grid app, where you've added an ApplicationController to deal with data context issues.

Frank


FR Frank Raab June 20, 2009 11:29 PM UTC

Further update:

I was able to make my test program work when I provided a column.Add for each and every column in the table. Does this mean I can't use a subset of columns in my grid, that I have to build a complete set of columns, then hide the ones I don't want to see?

Frank


FR Frank Raab June 22, 2009 03:01 PM UTC

Now I've spent a couple of days trying to make the grid work, and I've run into some strange behaviors.

My table has a primary key Guid called Id and another Guid reference called TemplateId. In the Html.Grid call I have

column.Add(p => p.Name);
column.Add(p => p.TemplateId);

When the grid is displayed, the Guid is that of the primary kay Id, not the TemplateId.

I also have a TemplateName text column in the table. If I add
column.Add(p => p.TemplateName);
I get the "Specified argument was out of the range of valid values" error, though none of the values are null or empty.

Do you have any explanation for these behaviors?

Frank


ML Muthukumar L Syncfusion Team June 24, 2009 12:33 PM UTC

Hi Frank,

Thanks for your interest in Syncfusion products.

We are glad to let you know Essential Studio ASP.NET MVC Edition Beta-4 has been launched successfully
Please download and use our latest version at
http://www.syncfusion.com/downloads
Updated Demo’s at
http://samples.syncfusion.com/mvcgriddemo/v7.2.0.39

Grid’s DataSource property accepts any kind of IEnumerable data source. It looks like you are trying to set SQL Query as data source.SQL Query cannot be directly set to datasource.

Please refer the following code snippet for setting data source.
Controller:

[C#]
public ActionResult Index()
{

/// HeaderText property is used to specify the Text to be displayed on the column header
MvcGridModel model = new MvcGridModel()
{
DataSource = MyProject.Models.MyDataContext.Orders.Skip(0).Take(20),
SkinName = "Syncfusion-Grid-Office2007Black",
ActionMode = "Server",
CaptionText = "Orders",
HeaderText = { "Order ID", "Customer ID", "Employee ID", "Ship Name", "Ship Address", "Ship City", "Ship Region", "Ship Postal Code", "Ship Country", "Ship Via", "Order Date", "Required Date", "Shipped Date", "Freight" },
PrimaryKeyColumns = { "OrderID" }
};

ViewData["GridModel"] = model;
return View();
}

View:
[ASPX]
// column.Add() is used add columns in the grid at desired order. This is used to filter out visible columns of the grid.
<%Html.Grid(

"MvcGridServerMode","GridModel" ,
column =>{
column.Add(p => p.OrderID);
column.Add(p => p.CustomerID);
column.Add(p => p.EmployeeID);
column.Add(p => p.ShipName);
column.Add(p => p.ShipAddress);
column.Add(p => p.ShipCity);
column.Add(p => p.ShipRegion);
column.Add(p => p.ShipPostalCode);
column.Add(p => p.ShipCountry);
column.Add(p => p.ShipVia);
column.Add(p => p.OrderDate);
column.Add(p => p.RequiredDate);
column.Add(p => p.ShippedDate);
column.Add(p => p.Freight);
}); %>


We are using SQLCE Data base .
The following code snippet is used in Application controller as connection string

[C#]
public MvcSampleBrowser.Models.Northwind SqlCE
{
get
{
AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
string connectionString = @"Data Source=|DataDirectory|\Northwind.sdf";
return new MvcSampleBrowser.Models.Northwind(connectionString);
}
}

/// SqlCE.Orders-> we can access Orders table from Northwind.sdf.

LINQ Support

Please visit our JSON samples, LINQ data source is used in the JSON mode.

Adding Subset of columns in the grid:


Please use the following lambda expression to add subset of columns what are all the columns are added here will be added to the visible columns collection and gets displayed, Where scenarios requires all columns to be displayed then the third parameter of the Grid() is not required. Options for adding HeaderText and Format from the view will be included in the coming Release.

There are two ways to achieving this

1)Adding visible column from view

[ASPX]
<%Html.Grid(
"MvcGridServerMode","GridModel" ,
column =>{
column.Add(p => p.OrderID);
column.Add(p => p.CustomerID);
column.Add(p => p.EmployeeID);
column.Add(p => p.ShipName);
}); %>

2)Adding visible columns from controller

[C#]
MvcGridModel model = new MvcGridModel();
model.TableDescriptor.VisibleColumns.Add("OrderID");
odel.TableDescriptor.VisibleColumns.Add("CustomerID");
model.TableDescriptor.VisibleColumns.Add("EmployeeID");
model.TableDescriptor.VisibleColumns.Add("ShipName");


3) TemplateId not Displayed Issue

We are unable to re-produce this issue. Nested table samples are available at

http://samples.syncfusion.com/mvcgriddemo/v7.2.0.39/gettingstarted/expand

Please refer our sample in the above link .If you are still facing problems please send us a sample illustrating the issue.

Please let us know if this helps you.

Regards,
Muthukumar.L


IR irfan replied to Muthukumar L March 12, 2018 06:01 AM UTC

Hi Samer,



Thanks for your interest in Syncfusion products.



The DatasourceType has to be mentioned in Grid’s HtmlHelperExtesion Method. Please refer to the following code snippet, in which Datasource type would be your Orders type.



<%Html.Grid(



"MvcGridServerMode","GridModel" ,



column =>{



column.Add(p => p.Id);



}); %>



Regards,

Muthukumar.L



Loader.
Live Chat Icon For mobile
Up arrow icon