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.
Related
I am using Kendo.Mvc.UI.TreeViewItemModel to build kendo treeview. Othe than Id and Text property this class also has HtmlAttributes property of type IDictionary<string, string>
I can add any additional data into HtmlAttributes property while building model, and kendo would render these Html Attributes as html data attribute on tree node.
public IEnumerable<TreeViewItemModel> BuildTreeView(IEnumerable<MyGroup> groups)
{
var nodes = new List<TreeViewItemModel>();
foreach (var grp in groups)
{
var root = new TreeViewItemModel()
{
Id = "0",
Text = grp.Key,
HasChildren = grp.Any()
};
foreach (var item in grp)
{
var dictionary = new Dictionary<string, string>();
dictionary.Add("data-template-id",item.TemplateID.ToString());
dictionary.Add("data-filename", item.FileName);
root.Items.Add(new TreeViewItemModel()
{
Text = item.DisplayText,
HasChildren = false,
HtmlAttributes = dictionary
});
}
nodes.Add(root);
}
return nodes;
}
cshtml
#(Html.Kendo().TreeView()
.Name("MyTreeView")
.DataTextField("Text")
.BindTo(Model.Items))
and then in JS i can access this data
var _treeView = $("#MyTreeView").getKendoTreeView();
var htmlItem = _treeView.select();
var templateid = htmlItem.data("template-id");
var filename = htmlItem.data("filename");
This is working fine as long as im using kendo's default template. However if i use custom template then Kendo does not generate data attributes
#(Html.Kendo().TreeView()
.Name("MyTreeView")
.TemplateId("treeViewItemTemplate")
.BindTo(Model.Items))
<script type="text/x-kendo-tmpl" id="treeViewItemTemplate">
<span>#=item.text#</span>
# if (!item.items){#
<span class="glyphicon glyphicon-plus-sign" aria-hidden=true></span>
#}#
</script>
now when the page renders and using F12 if look at the tree node ( which is li tag) i don't see any data attributes
I have switched from HtmlWorker to XMLWorker in order to take advantage of the use of external css files. Besides, in this way, I avoid the use of inline styling.
This is currently my code:
public ActionResult ViewPdf(object model)
{
var doc = new Document(PageSize.A3, 10f, 1f, 10f, 30f);
var memStream = new MemoryStream();
var writer = PdfWriter.GetInstance(doc, memStream);
writer.CloseStream = false;
doc.Open();
var xmltext = RenderActionResultToString(View(model));
var htmlContext = new HtmlPipelineContext(null);
htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
var cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
cssResolver.AddCssFile(Server.MapPath("~/Content/StyleSheet1.css"), true);
var pipeline = new CssResolverPipeline(cssResolver,
new HtmlPipeline(htmlContext, new PdfWriterPipeline(doc, writer)));
var worker = new XMLWorker(pipeline, true);
var parser = new XMLParser(worker);
using (var sr = new StringReader(xmltext))
{
parser.Parse(sr);
}
doc.Close();
var buf = new byte[memStream.Position];
memStream.Position = 0;
memStream.Read(buf, 0, buf.Length);
return new BinaryContentResult(buf, "application/pdf");
}
RenderActionResultToString(View(model)) is giving me the string I want to parse into pdf. This all works fine. The problem is with the styles. If I use inline styling such as:
<table style ="width: 400px">
, everything works like a charm. But if I use something like:
<table class = "foo">
, and reference a css file(StyleSheet1.css) like this:
.foo {
width: 400px;
}
, it doesn't work...
I tried referencing the stylesheet in the string I am parsing, like this in my view:
<head>
<link href ="#Server.MapPath("~/Content/StyleSheet1.css")" rel ="stylesheet" type="text/css"/>
</head>
I inserted the link to the css file just as the documentation states, inside the head tags.
Thanks in Advance
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
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");
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