razor

如何在Razor视图页面中导入名称空间?

ぐ巨炮叔叔 提交于 2019-12-22 21:56:23
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 如何在Razor视图页面中导入名称空间? #1楼 终于找到答案了。 @using MyNamespace 对于VB.Net: @Imports Mynamespace 如果要在整个应用程序中包含名称空间,请查看@Javad_Amiry的答案。 #2楼 在ASP.NET MVC 3 Preview1中,可以使用Global.asax.cs中的此代码在所有剃刀视图上导入名称空间 Microsoft.WebPages.Compilation.CodeGeneratorSettings.AddGlobalImport("Namespace.Namespace"); 我希望在RTM中可以通过Web.config部分完成操作。 #3楼 我认为为了在剃刀视图中导入名称空间,您只需要添加以下方式: @using XX.YY.ZZ #4楼 对于图书馆 @using MyNamespace 对于模型 @model MyModel #5楼 你可以试试这个 @using MyNamespace 来源: oschina 链接: https://my.oschina.net/u/3797416/blog/3145989

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

牧云@^-^@ 提交于 2019-12-22 21:42: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

MVC5 Autofac: The view found at was not created

橙三吉。 提交于 2019-12-22 20:02:46
问题 I created very simple MVC 5.0 application that I push to GitHub repository: https://github.com/marxin/mvc-sample. My motivation is to execute app on Linux with mono 3.2.3. I would like to add Autofac NuGet package (more precisely 3.3.0), that works fine for me. Problem is that if I add Autofac.Mvc5 integration package, Razor stops working with following error: System.InvalidOperationException The view found at '~/Views/Home/Index.cshtml' was not created. Description: HTTP 500.Error processing

Row & column alignment when dynamically adding rows to a html table using BeginCollectionItem in ASP.NET MVC 3 using jQuery

青春壹個敷衍的年華 提交于 2019-12-22 18:30:35
问题 I have the following html table definition in my main view <table id="myDynamicTable" cellpadding="0" cellspacing="0" class="burTable" width="964px"> <thead> <tr> <th style="white-space: nowrap;display: inline;width: 40px" > ColOne </th> <th style="white-space: nowrap;display: inline;width: 90px"> ColTow </th> <th style="white-space: nowrap;display: inline;width: 54px"> ColThree </th> <th style="white-space: nowrap;display: inline;width: 60px"> ColFour </th> <th style="white-space: nowrap

Accessing the property of a model in ASP.NET MVC View

独自空忆成欢 提交于 2019-12-22 16:53:44
问题 I am having problems accessing one of the properties of the model I am passing a View. The model is defined like this: public class ProductBasket { public ProductBasket() { Products = new List<ProductConfiguration>(); Errors = new List<string>(); } public List<ProductConfiguration> Products { get; set; } public List<string> Errors { get; set; } } In my view the model directive is declared like this: @model MyApp.ViewModels.Product.ProductBasket I am unable to access the Products property in a

ASP.NET MVC how to handle 404 error from Application_Error without rewriting the URL

北城以北 提交于 2019-12-22 14:54:33
问题 I have created a really simple ASP.NET MVC 5 application where i want to handle the 404 exception from my Application_Error as shown in this question and in this other answer . But when i try to reach a page who don't exist (and expect my 404 page to be displayed) the source code of my custom error page is shown in plain text! . I don't want my URL to be rewrited as in this post My project is really simple. I just added to a basic ASP.NET WebApplication with Razor : an ErrorsController.cs a

MvcRazorToPdf - images not rendering, MVC4

一世执手 提交于 2019-12-22 14:47:13
问题 I have been trying to render an image but with no positive result. Is there anything specific I need to add to make it work. I am not including the rest of the View which renders fine, but in the pdf, the image is missing. I have followed the below link: https://github.com/andyhutch77/MvcRazorToPdf View @model Test.Models.PdfExample @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; var imagePath = Server.MapPath("~/Content/Images"); } <div style="width: 200%; height: 80px;

ASP.NET MVC3 - If Statements in VB

允我心安 提交于 2019-12-22 11:35:21
问题 In Fredrik's Blog post, he has an example of a C# if statement @if (WebSecurity.IsAuthenticated) { <li><a href="/user/login">Log in</a></li> } else { <li><a href="/user/logout">Log out</a></li> } But in VB I can't seem to figure out how to do the same thing @If (HttpContext.Current.User.Identity.IsAuthenticated) Then <div id="dialog-confirm" title="Log Out"> <div class="alert" title="Alert"> </div> Are you sure?</div> End If This show's that my internal HTML markup is wrong. Basically the

How Decode HTML in MVC with RAZOR

风流意气都作罢 提交于 2019-12-22 11:07:34
问题 I'm using MVC 3 and Razor as View Engine, for my understanding HTML tags are decoding by default to prevent XSS attacks or similar. (I'm also using MS XSS 4.2.1 Library) I have a View showing some data <div class="display-label">Code</div> <div class="display-field"> @Html.DisplayFor(model => model.Code). </div> Model.Code is HTML code for some Banners, I need to display the HTML on the page DECODED. My question: How can I decode the HTML for just model.Code living the rest ENCODED? Thanks

Html.PasswordFor is not populated?

点点圈 提交于 2019-12-22 11:06:04
问题 I spend a lot of my time, trying to understand why in a razor expression of @HTML.PasswordFor( m => m.Password) I can't set the value from the model the only solution that I found it's injecting the value by html properties like this @HTML.PasswordFor( m => m.Password, new { value = Model.Password }) Am I doing something wrong?? is the correct helper?? this is the field model configuration [Required(ErrorMessage = "La contraseña es obligatoria.")] [StringLength(100, ErrorMessage = "El {0}