razor-2

Load views from location outside the mvc website

不想你离开。 提交于 2019-12-08 10:06:59
问题 I'm trying to load an MVC view form a folder outside the location of the app. My app is in C:\dev\myproject\ and the view file i'm trying to load is located in D:\viewsfolder\something is it possible to do that? I tried passing an absolute path to the return View() method but that didn't work. 回答1: This is not supported by standard ASP.NET MVC. You may take a look at the RazorEngine plugin which allows you to render a Razor view from a string. You haven't really explained why you need to do

Relative Path tilde (~) not working in ASP.NET MVC 4

谁说胖子不能爱 提交于 2019-12-08 01:52:40
问题 When I run my project on my machine, it runs on http://localhost:53998/ but when I deploy it to http://test.myserver.com/MyApp/ all links break. I'm using the relative path tilde ( ~ ), so a navigation link would be something like: <a href="~/SomeCtrl/Index">Some Action</a> On localhost, this works fine (when root is / ), but when I deploy my project under /MyApp/ it links the action to http://test.myserver.com/SomeCtrl/Index instead of http://test.myserver.com/MyApp/SomeCtrl/Index so I

Razor conditional attribute not working

假装没事ソ 提交于 2019-12-07 07:16:35
问题 In a tag I want to conditionally output the style attribute, e.g.: <li style="@styleVar" >...</li> When styleVar is null it should not be written by razor (just the supposed standard functionality in Razor 2), but for some strange reason it is outputted as <li style="">...</li> , while I expect <li>...</li> . This is in a partial view. In a normal view it is working. So is this a bug in partial views? Anybody the same experience? 回答1: This does not seem to work in partial views and for custom

Error 22 The “EnsureBindingRedirects” task could not be loaded from the assembly

不打扰是莪最后的温柔 提交于 2019-12-06 16:35:19
问题 I cloned a project with vs 2013. When I run it I get this error. Error 1 The "EnsureBindingRedirects" task could not be loaded from the assembly D:\BMaster\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.Tasks.dll. Could not load file or assembly 'file:///D:\BMaster\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly

Relative Path tilde (~) not working in ASP.NET MVC 4

醉酒当歌 提交于 2019-12-06 15:22:51
When I run my project on my machine, it runs on http://localhost:53998/ but when I deploy it to http://test.myserver.com/MyApp/ all links break. I'm using the relative path tilde ( ~ ), so a navigation link would be something like: <a href="~/SomeCtrl/Index">Some Action</a> On localhost, this works fine (when root is / ), but when I deploy my project under /MyApp/ it links the action to http://test.myserver.com/SomeCtrl/Index instead of http://test.myserver.com/MyApp/SomeCtrl/Index so I always get a 404. Isn't this what the tilde ( ~ ) should take care of? Am I doing something wrong here? EDIT

RazorEngine extension method fails with RuntimeBinderException after upgrade to Razor 2/ RE 3.2

泄露秘密 提交于 2019-12-06 07:01:44
I have a RazorEngine project that fails following an upgrade to Razor 2.0 and RazorEngine 3.2.0 This worked fine in the previous Razor 1.0 based version of RazorEngine (3.0.8). I have an instance ( myInstance ) of a class ( MyClass ) and and extension method: namespace MyCompany.Extensions { public static class MyClassExtensions { public static string ExtensionMethod(this MyClass thing) { // do stuff } } } I want to call this in a RazorEngine view (simplified example, there are loads of these methods, and all fail the same way): @using MyCompany.Extensions @using MyCompany @{ var myInstance =

Razor conditional attribute not working

一曲冷凌霜 提交于 2019-12-05 17:15:07
In a tag I want to conditionally output the style attribute, e.g.: <li style="@styleVar" >...</li> When styleVar is null it should not be written by razor (just the supposed standard functionality in Razor 2), but for some strange reason it is outputted as <li style="">...</li> , while I expect <li>...</li> . This is in a partial view. In a normal view it is working. So is this a bug in partial views? Anybody the same experience? This does not seem to work in partial views and for custom html attributes such as data-test="@test". This is not omitted, instead it still puts in the data-test="".

MVC4 ViewData.TemplateInfo.HtmlFieldPrefix generates an extra dot

你。 提交于 2019-12-05 04:33:57
I'm trying to get name of input correct so a collection of objects on my view model can get bound. @{ViewData.TemplateInfo.HtmlFieldPrefix = listName;} @Html.EditorFor(m => m, "DoubleTemplate", new { Name = listName, Index = i, Switcher = (YearOfProgram >= i +1) }) As you can see here, I pass in the "listName" as the prefix for my template. the value of listName = "MyItems" And here is my template: @model Web.Models.ListElement @if (ViewData["Switcher"] != null) { var IsVisible = (bool)ViewData["Switcher"]; var index = (int)ViewData["Index"]; var thisName = (string)ViewData["Name"] + "[" +

Error 22 The “EnsureBindingRedirects” task could not be loaded from the assembly

天涯浪子 提交于 2019-12-04 22:16:52
I cloned a project with vs 2013. When I run it I get this error. Error 1 The "EnsureBindingRedirects" task could not be loaded from the assembly D:\BMaster\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.Tasks.dll. Could not load file or assembly 'file:///D:\BMaster\packages\Microsoft.Bcl.Build.1.0.13\tools\Microsoft.Bcl.Build.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements

Using If statement in a MVC Razor View

こ雲淡風輕ζ 提交于 2019-12-03 13:13:57
In the following code, If I use "@If" statement ,I get the following compile code error as " The name 'grid' does not exist in the current context. @if (Model.SModel != null) { @{ WebGrid grid = new WebGrid(Model.SModel); } } else { } @grid.GetHtml() , But the code compiles without the "If" statement.For example @{ WebGrid grid = new WebGrid(Model.SModel); } @grid.GetHtml(). What is the syntactical error in using If else statement grid isn't declared outside of the scope of your if statment. Try this instead: @if (Model.SModel != null) { WebGrid(Model.SModel).GetHtml() } I would try this: @if