How to display array in MVC3? - asp.net-mvc-3

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

Related

Umbraco problem getting chilld properties

I have Umbraco Content List containing multiple Umbraco Content pages. When I try to find some content page properties like Page Title or Heading or bodyText I'm getting "The function evaluation requires all threads to run.". Here is my code.
#using Umbraco.Web
#using Umbraco.Web.Mvc
#{
Layout = "T";
}
#{
var UContentList = Model.Content.Children;
var SContentList = new List<MyProgram.Models.MyContent>();
foreach (var uContent in UContentList)
{
var SContent = new IMyProgram.Models.MyContent(
uContent.pageTitle.ToString(),
uContent.contentExcerpt.ToString()
);
SContentList.Add(SContent);
}
Please help how do I get the values from these properties
I've managed to do it. First need to debug and do this: https://blogs.msdn.microsoft.com/eliofek/2012/12/12/why-do-we-get-the-function-evaluation-requires-all-threads-to-run/
Then here is the source:
#inherits UmbracoTemplatePage
#using Umbraco.Web
#using Umbraco.Web.Mvc
#using ContentModels = Umbraco.Web.PublishedContentModels;
#{
/**/
Layout = "";
}
#{
var UContentList = Model.Content.Children();
var SContentList = new List<MyProgram.Models.MyContent>();
foreach (var uContent in UContentList)
{
var SContent = new MyProgram.Models.MyContent(
uContent.GetPropertyValue("pageTitle").ToString(),
uContent.GetPropertyValue("contentExcerpt").ToString(),
uContent.Url.ToString()
);
SContentList.Add(SContent);
}
The difference is the #inherits and #using ContentModels.

How to get viewbag data in Asp.net MVC?

How to get viewbag data, i created one controller in that data is fetch from data base and try to show the data in view but it is not displaying data.
public ActionResult Show()
{
List<Models.Employees> lst = new List<Models.Employees>();
Models.Employees obj = new Models.Employees();
DataSet ds =new Models.BL.InsertBL().GetShow(obj);
lst = (from DataRow drw in ds.Tables[0].Rows
select new Models.Employees
{
Enames = drw["Ename"].ToString(),
DepartId =Convert .ToInt32(drw["Departmentid"]),
EmailIds = drw["Emailid"].ToString(),
Adress = drw["Address"].ToString()
}).ToList();
ViewBag.Sasi = lst;
return View();
}
#{
ViewBag.Title = "Show";
Layout = "~/Views/Shared/VideoLayout.cshtml";
var vv = ViewBag.Sasi;
}
In this scenario I would recommend you strongly typed views:
return View(lst);
and in View:
#model List<Models.Employees>
Your question, try this:
(List<Models.Employees>)ViewBag.Sasi

dropDownList doesn't show real data

i have added the model in my view:
#model Tuple<List<EshopTheme.Areas.Administrators.Models.ThemeGroupsModel>,
EshopTheme.Areas.Administrators.Models.AdminModel,
EshopTheme.Areas.Administrators.Models.ThemesModel>
in my Controller i have added this action:
public ActionResult AddTheme()
{
AdminSrv adminService = new AdminSrv();
AdminModel adminModel = new AdminModel();
ThemesModel themeModel = new ThemesModel();
Tuple<List<ThemeGroupsModel>, AdminModel, ThemesModel> tuple =
new Tuple<List<ThemeGroupsModel>, AdminModel, ThemesModel>
(adminService.getAllThemeGroupByAdmin(), adminModel, themeModel);
return View(tuple);
}
i have used this DropDownListFor :
#Html.DropDownListFor(x => x.Item1, new SelectList(Model.Item1))
but, DropDownListFor , shows the list of:
EshopTheme.Areas.Administrators.Models.ThemeGroupsModel
EshopTheme.Areas.Administrators.Models.ThemeGroupsModel
EshopTheme.Areas.Administrators.Models.ThemeGroupsModel
why?????????????
this is my getAllThemeGroupByAdmin() code:
public List<ThemeGroupsModel> getAllThemeGroupByAdmin()
{
List<ThemeGroupsModel> ThemeGr = new List<ThemeGroupsModel>();
ThemeGroupsModel ThemeGrTemp;
using (var context = new EShopThemeDBEntities(idbconnection.ConnStr))
{
var ThemeGroupList = (from o in context.ThemeGroups
select o).ToList();
foreach (var item in ThemeGroupList)
{
ThemeGrTemp = new ThemeGroupsModel();
ThemeGrTemp.ThemeGroupName = item.ThemeGroupName;
ThemeGrTemp.ThemeGroupId = item.ThemeGroupID;
ThemeGr.Add(ThemeGrTemp);
}
}
return ThemeGr;
}
You should use Text and Value property;
SelectList selectList = new SelectList(selectListItems, "Value", "Text");

simple dropdown list

i did not found simple dropdown list .
i'm new in mvc3
this part create and fill : ListMonitoringLicenseModelList = new List();
i fill this objectsList in another part and use it to fill MonitoringLicenseModelList
objectsList = new List(...fill objectsList...);
List<MonitoringLicenseModel>MonitoringLicenseModelList = new List<MonitoringLicenseModel>();
foreach (object o in objectsList)
{
string[] tmpString = o.ToString().Split('#');
int i = 0;
monitoringLicenseModel = new MonitoringLicenseModel();
monitoringLicenseModel.MonitoringID =Convert.ToInt32(tmpString[i++]);
monitoringLicenseModel.LicenseUI = tmpString[i++];
MonitoringLicenseModelList.Add(monitoringLicenseModel);
}
public ActionResult SchedulesIndex()
{
return View(MonitoringLicenseModelList);
}
how can i write dropdownlist to show this
name value
MonitoringID = LicenseUI
#model List<MonitoringLicenseModel>
...
#Html.DropDownList(
"SelectedMotoringID",
new SelectList(Model, "MonitoringID", "LicenseUI")
)

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