creating control array in razor - asp.net-mvc-3

How to create control array in razor or asp.net-mvc3?

var j=0;
$('input[type=text]').each(function (e) {
$(this).addClass('txt_' + j)
j++;
}
You can add class dynamically for each textbox. j is the number of textbox.

If you need input array you can do this:
#model List<mymodel>
for(int i = 0; i < Model.Count; i++)
{
#Html.EditorFor(model => model[i].SomeProperty)
}

Related

LINQ Group by with dynamic multiple parameters to splits datatable as multiple datatables in C#

I want to split datatables from one datatable by dynamic column name.
Now dynamic column names is not work.
for (int i = 0; i < nameList.Count; i++)
{
// a = r["a"]
b += nameList[i] +"="+ "r[\"" + nameList[i] + "\"]";
if (i != nameList.Count - 1)
{
b += ",";
}
}
for (int i = 0; i < nameList.Count; i++)
{
dataTableList = dtDataList.AsEnumerable().GroupBy(row
=> new { b}).Select(row => row.CopyToDataTable()).ToList();
}
}

Kendogrid population

I'm new to all this kendo stuff i need help in populating kendogrid from a csv file.
The csv data is stored in an array of strings returned by a service.
Data looks like :
0: "Module,LogLevel,LogType,LoggedTime,LogMessage"
1: "00D02D5A4B66 ,CommServer ,Level3 ,Information ,03/16/2015 00:32:57:5716 ,[ISOMMessageHandler::Initialize]-[EventCount:20,ObjectRetryCount:6]"
2: "00D02D5A4B66 ,CommServer ,Level1 ,Information ,03/16/2015 00:32:57:5716 ,ISOMProtocolHandler::HandleConnectGeneric] - Before UpdatePanelTouched - CommServerID : 1, ConnectionMode : 2"
3: "00D02D5A4B66 ,CommServer ,Level4 ,Information ,03/16/2015 00:32:57:5716 ,[PanelDataConfigurationHandler : UpdatePanelConnectionStatus] : CommServerID 1, CommMode : 2"
i need to display 0th indexed data as title of the columns
and rest in cells of the column.
My advice is to make a wrapper method yourself and get it into JSON.
needed wrapper as told by Thomas.
here is my wrapper function
function csvJSON(lines) {
var result = [];
var headers = lines[0].split(",");
headers.unshift("MAC");
for (var i = 1; i < lines.length; i++) {
var obj = {};
var currentline = lines[i].split(",");
for (var j = 0; j < headers.length; j++) {
obj[headers[j]] = currentline[j];
}
result.push(obj);
}
return result;
}

using array in Kendo Grid binding

one of my model field is an array and when I attempting to use it to bound grid column in ASP.NET MVC and use of Kendo Grid I get error: "bound columns require a field or property access expression"
for(var i=0; i<10 ; i++)
columns.Bound(p => p.Value[i])
using template also couldn't solve my problem.
You should be able to use a template to do whatever you need to with that columns.
See sample http://jsbin.com/uxefaMI/2/edit
I use a template to sum up each of the values in the array
function numbersTemplate(e) {
var total = 0;
$.each(e.numbers, function(i, n) {
total += parseInt(n, 0);
});
return total;
}
I found my error.
Basically the grid columns can be bound only to the object properties. In current case I was trying to bind the column to the values of given property which is invalid configuration. Example below shows how to rendering the given property values in current column using ClientTemplate:
e.g.:
columns.Bound(p => p.Value).ClientTemplate("#=generateTemplate(Value)#");
function generateTemplate(Value) {
var template = "<ul>";
for (var i = 0; i < Value.length; i++) {
template = template + "<li>" + Value[i] + "</li>";
}
return template + "</ul>";
}

Telerik: RadComboBox How do delete all the items and add a new list

I am using a telerik radcombobox for a drop down list inside a user control in a web forms application. I need to delete all the items in the box, let's say id is ddlVeihicleMake and repopulate it with a new list of item passed to the function. Here is an example of what I understand it should be like,
function addNewItems(selectRef, optionsArray, valuesArray) {
var combo = document.getElementById("ctl00_cpMain_ctl01_appRadPaneltabVehicleInformation_i0_i0_tabVehicleInformation_ddlVehicleMake_Input");
combo.get_items().clear();
for (var idx = 0; idx < optionsArray.length; idx++) {
if (valuesArray == "") {
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
comboItem.set_text(optionsArray[idx]);
combo.trackChanges();
combo.get_items().add(comboItem);
} else {
var comboItem = new Telerik.Web.UI.RadComboBoxItem();
comboItem.set_text(optionsArray[idx]);
combo.trackChanges();
combo.get_items().add(comboItem);
}
}
It fails for me on get_items().clear() and get_itmes().add(comboItem). Appreciate any help I can get.
Thanks!
Try something like this:
function DeleteItems(sender, args)
{
var combo = window.$find("<%= cboMyComboBox.ClientID %>");
combo.trackChanges();
for (var i = 0; i < combo.get_items().get_count(); i++) {
combo.get_items().remove(combo.get_items().getItem(i));
}
combo.commitChanges();
}

MVC3 Razorview syntax

I have the following in my view:
#{ var index = 0; }
#foreach (var item in Model)
{
...
#{
index += 1;
}
}
but i get
No overload for method 'Write' takes 0
arguments
what gives?
thanks
i believe it should be...
#{ var index = 0; }
#foreach (var item in Model)
{
index += 1;
}

Resources