razor

Expression of HelperResult to format item from a list

假装没事ソ 提交于 2019-12-23 11:52:22
问题 I'm doing a component to format a list, it is an Extension, I wrote the following code, but, when in execution time, it gives me the error: Cannot convert lambda expression to type 'System.Web.WebPages.HelperResult' because it is not a delegate type This is the extension: public static MvcHtmlString FormatMyList<TModel, TValue>(this HtmlHelper<TModel> htmlHelper, IEnumerable<TValue> list, Expression<Func<TValue, System.Web.WebPages.HelperResult>> formatExp = null) { foreach (var item in list)

The view must derive from WebViewPage

爱⌒轻易说出口 提交于 2019-12-23 10:16:31
问题 I had a working MVC application when I decided that it was time for some maintenance. My views were all under SHARED directory and I decided to move them into separate directories. I implemented a CustomViewEngine that I found here: Can I specify a custom location to "search for views" in ASP.NET MVC? View structure looks something like this Views AppViews OtherAppViews ... Shared ... This is an error that I am getting: The view at '~/Views/AppViews/SomeView.cshtml' must derive from ViewPage,

The view must derive from WebViewPage

醉酒当歌 提交于 2019-12-23 10:15:06
问题 I had a working MVC application when I decided that it was time for some maintenance. My views were all under SHARED directory and I decided to move them into separate directories. I implemented a CustomViewEngine that I found here: Can I specify a custom location to "search for views" in ASP.NET MVC? View structure looks something like this Views AppViews OtherAppViews ... Shared ... This is an error that I am getting: The view at '~/Views/AppViews/SomeView.cshtml' must derive from ViewPage,

Use ToString() with @Html.DisplayFor

戏子无情 提交于 2019-12-23 09:57:04
问题 Why can't I use ToString("#.##") with a @Html.DisplayFor such as: @Html.DisplayFor(modelItem => modelItem.Balance.ToString("#.##")) 回答1: when I've encountered this before, I simply added a Getter to the model that the View consumes. public string FormattedBalance { get { return this.Balance.ToString("#.##"); } } And then just use it in your view: @Html.DisplayFor(ModelItem => ModelItem.FormattedBalance) 回答2: The DisplayFor renders the default ToString method for the supplied model property.

How can a razor for loop be used in a javascript script tag?

烈酒焚心 提交于 2019-12-23 09:48:16
问题 The error generated is "Conditional Compilation is turned off". Conditional Compilation hack from MSDN is prevalent but fails. There are several questions like this one: Conditional Compilation is turned off in Razor? They all point to the answer of: /*@cc_on @*/ From the article seen here at the MSDN: http://msdn.microsoft.com/en-us/library/5y5529x3(v=vs.90).aspx However, this hack is pretty fail or I seem to fail at implementing it. The trailing @* causes the remaining code in the .cshtml

How can I debug mvc4 razor views?

℡╲_俬逩灬. 提交于 2019-12-23 09:12:09
问题 I'm used to C# and vb.net winforms, and usually can find all the errors I need just by setting a breakpoint and stepping through my code. I would like to know what I'm doing wrong. I'm placing a breakpoint here: public ActionResult Index(int id) { var cnty = from r in db.Clients where r.ClientID == id select r; if (cnty != null) // breakpoint here { return View(cnty); // F11 jumps over this section of code returning me to the error page below. } return HttpNotFound(); } Yet again I have no

How to Link to OData Collection in Razor using ASP.NET MVC Web API OData

一世执手 提交于 2019-12-23 09:11:07
问题 I have an ASP.NET MVC 4 app that i'm incorporating an OData API into. This is running the 2012.2 stuff with the larger OData support. I did not use a separate area for this...that might have been a mistake but my app is small and area seemed overkill. I've got my controllers setup correctly and an example path to my Segments collection (segments is a type in my domain) is "/odata/Segments". This loads as expected and is working. On my homepage i'm trying to add a link to this resource using

How can I debug mvc4 razor views?

那年仲夏 提交于 2019-12-23 09:09:01
问题 I'm used to C# and vb.net winforms, and usually can find all the errors I need just by setting a breakpoint and stepping through my code. I would like to know what I'm doing wrong. I'm placing a breakpoint here: public ActionResult Index(int id) { var cnty = from r in db.Clients where r.ClientID == id select r; if (cnty != null) // breakpoint here { return View(cnty); // F11 jumps over this section of code returning me to the error page below. } return HttpNotFound(); } Yet again I have no

Use Bower package version numbers in Razor views for CDN support

ⅰ亾dé卋堺 提交于 2019-12-23 08:49:52
问题 I am using Bower in Visual Studio 2017 to install packages such as Bootstrap and jQuery. In my views I am referencing the same libraries using a CDN like so: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css" asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.css" asp-fallback-test-class="glyphicon" asp-fallback-test-property="visibility" asp-fallback-test-value="hidden" /> If I change the version of Bootstrap in Bower from 3.3.7 to something

.net MVC passing linq data from controller to view

非 Y 不嫁゛ 提交于 2019-12-23 08:45:13
问题 I am trying to pass data from controller to view. I have searched the web but could not find a solution. if I do this it works: Controller: var yyy = (from a in Connection.Db.Authorities select a) ; ViewBag.data = yyy; View: @foreach(var item in ViewBag.data) { @item.Value } But the following code does not work: Controller: var yyy = (from a in Connection.Db.Authorities select new {Value = a.Value, TypeCode = a.TypeCode, Return = Calculate(a.Return)}) ; ViewBag.data = yyy; View: @foreach(var