MVC3 Razorview syntax - asp.net-mvc-3

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;
}

Related

how to iterate literal dictionary in cappucino objective-j

Please an help to iterate literal dictionary on cappuccino environment.Thanks
var userDict = #{#"name": #"Jack",#"secondName": #"Buck",#"name": #"Jacob",#"secondName": #"Smith"};
for (var righe in userDict){
console.log(righe.name + righe.secondName);
}
output NaN
I'd probably do something like this:
for (var key in [userDict allKeys])
{
console.log(key, userDict[key]);
}
But your dictionary looks wrong; this:
#{
#"name": #"Jack",
#"secondName": #"Buck",
#"name": #"Jacob",
#"secondName": #"Smith"
};
Will overwrite the name and secondName indices and result in:
#{
#"name": #"Jacob",
#"secondName": #"Smith"
};
You probably wanted a CPArray of CPDictionary:
var users = [
#{
#"name": #"Jacob",
#"secondName": #"Smith"
},
#{
#"name": #"Jacob",
#"secondName": #"Smith"
}
];
Then if you loop over users; you get one user dictionary for each step in the loop, and you can address its ' indices (properties).
Since both CPArray and CPDictionary are tollfree-bridged to their native javascript counterparts, you can still do this:
for (var ix = 0; ix < users.length; ix ++)
{
var user = users[ix];
console.log(user.name, user.secondName);
}
Hope this helps.

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();
}

How to display array in MVC3?

Hello friends I get datas from Web services so I can't use Html.DisplayFor(model=>model.item)and how can I display datas in array. Here is my code:
#using icerik.TahakkukServices
#{
ViewBag.Title = "Deneme";
Layout = "~/Views/Shared/_Layout5.cshtml";
}
#{
TahakkukServicesClient client = new TahakkukServicesClient();
client.ClientCredentials.UserName.UserName = "service_test";
client.ClientCredentials.UserName.Password = "";
client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
MakbuzList[] liste = client.GetMakbuzListe(2);
}
#foreach (var item in liste)
{
Html.DisplayFor(item.Adi)
}
#model icerik.TahakkukServices. add your table name
#{
ViewBag.Title = "Deneme";
Layout = "~/Views/Shared/_Layout5.cshtml";
}
#{
TahakkukServicesClient client = new TahakkukServicesClient();
client.ClientCredentials.UserName.UserName = "service_test";
client.ClientCredentials.UserName.Password = "";
client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
MakbuzList[] liste = client.GetMakbuzListe(2);
}
#foreach (var item in liste)
{
Html.DisplayFor(model=>model.) add your column name
}
Allright I understand how to do it just giving model name with your Service as you can see at below
#model icerik.TahakkukServices.Borc
so you can use Html.DisplayFor

creating control array in razor

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)
}

Expand all items in RadGrid Hierarchy

I am using a RadGrid (2009 Q2) with a hierarchy. Is there a way in the client api to expand all rows and vice-versa?
thanks!
Update:
I have written a javascript function based off the api documentation suggested by Dick Lampard below to expand/collapse all rows in a radgrid with three levels. It expands all the mastertableview rows and all the nested detailtableview rows in both sub levels of the first mastertableview row, but it breaks when it goes the to detailtableview rows for the second mastertableview row (whew!). The error I am getting is "_350 is undefined". This is coming from a Telerik.Web.UI.WebResource file.
function ExpandCollapseAll(expand) {
var grid = $find("<%= rgHistory.ClientID %>");
master = grid.get_masterTableView();
var masterRowCount = master.get_dataItems().length;
for (masterIndex = 0; masterIndex < masterRowCount; masterIndex++) {
if (expand) {
master.expandItem(masterIndex);
}
else {
master.collapseItem(masterIndex);
}
}
var detailTables = grid.get_detailTables();
var detailTableCount = detailTables.length;
for (detailTableIndex = 0; detailTableIndex < detailTableCount; detailTableIndex++) {
var detailTable = detailTables[detailTableIndex];
var rowCount = detailTable.get_dataItems().length;
for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {
if (expand) {
//expandItem is failing! detailTableIndex and rowIndex are correct
detailTables[detailTableIndex].expandItem(rowIndex);
}
else {
detailTables[detailTableIndex].collapseItem(rowIndex);
}
}
}
}
ANY IDEAS?!?!
There is client API for hierarchy expansion as well as ExpandHierarchyToTop() server method. Check out this demo.
Dick
If you would like to see all the hierarchy levels, Set HierarchyDefaultExpanded to the MasterTableView and all the GridTableViews. See this link for more details.
Try This
protected void Page_PreRenderComplete() {
if (!Page.IsPostBack) {
foreach (GridItem item in MyGrid.MasterTableView.Controls[0].Controls) {
if (item is GridGroupHeaderItem)
if (item.GroupIndex.ToString() != "0")
item.Expanded = !item.Expanded;
}
}
}
after radGrid.DataBind()
use this Mehtod
private void ExpanadAllRadGridNodes()
{
foreach (GridDataItem item_L1 in radgridQuestionGroups.MasterTableView.Items)
{
foreach (GridTableView item_L2 in (item_L1 as GridDataItem).ChildItem.NestedTableViews)
{
foreach (GridDataItem item_L3 in item_L2.Items)
{
item_L3.Expanded = true;
}
}
}
}

Resources