Tag: razor

设置’cshtml’数据并返回一个字符串

我有一个确认电子邮件模板.cshtml如下: company name: Email Verification – Action Required Thanks for signing up for company name! Thank you for signing up to company name. Please press the link below to confirm your email address If you did not sign up for company name, please ignore this email, and accept our apologies for the inconvenience. https://stackoverflow.com/questions/33463224/set-cshtml-data-and-return-a-string/@Model.ConfirmLink Thanks, […]

如何在将C#字符串传递给javascript时优雅地转义单引号和双引号

我有一个C#字符串需要传递给页面然后发送回服务器。 它需要能够处理单引号,双引号和可能导致问题的任何其他标准字符。 我正在使用MVC4和razor。 现在我将字符串传递给javascript。 我有这样的事情: var str = ‘@Html.Raw(Model.SomeString.Replace(“‘”, @”\'”))’; 这很好用,但我想知道是否有更好,更优雅的方式来转义将传递给javascript的C#字符串。 我已经尝试将值存储在隐藏字段中,如下所示: @Html.Hidden(x => x.SomeString) 但是当我去抓取价值时,它会出现双引号问题。 编辑:结果是Html.Hidden问题是由其他东西引起的 任何帮助是极大的赞赏! 注意:必须在IE9和10中工作。没有ViewBags。

使用Razor的FormsAuthentication无效

我试图让FormsAuthentication与我的Razor应用程序(MVC 3)一起使用。 我有一个LoginController调用我的LoginPage(在Views / Shared中); 我的web.config将LoginUrl设置为“/ Login /”。 当应用程序尝试调出主页面时,[Authorize]行会正确显示LoginPage,但问题就出现了。 这是我的LoginController.cs: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace ABMCEditAndReports.Controllers { public class LoginController : Controller { // // GET: /Login/ public ActionResult Index() { return View(“LoginPage”); } } } 这是我的LoginPage.cshtml: @{ ViewBag.Title = “Login Page”; ViewBag.Header = “Login Page”; } $.ajaxSetup({ cache: […]

MVC Razor:Helper导致html.actionlink

我有一个帮手,我可以这样打电话没问题: Helpers.Truncate(post.Content, 100); 但是当我在@Html.ActionLink中调用它时,我得到以下错误: Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1928: ‘System.Web.Mvc.HtmlHelper<System.Collections.Generic.IEnumerable>’ does not contain a definition for ‘ActionLink’ and the best extension method overload ‘System.Web.Mvc.Html.LinkExtensions.ActionLink(System.Web.Mvc.HtmlHelper, string, string, object, object)’ […]

在另一个程序集中找到Razor Pages

我想在另一个程序集中找到My Project Razor Pages。 为此,我写下面的代码: public void ConfigureServices(IServiceCollection services) { var adminAssembly = Assembly.Load(new AssemblyName(“App”)); services.AddMvc().AddApplicationPart(adminAssembly).AddRazorOptions(options => { var previous = options.CompilationCallback; options.CompilationCallback = context => { previous?.Invoke(context); context.Compilation = context.Compilation.AddReferences( MetadataReference.CreateFromFile(typeof(dodo).Assembly.Location)); }; }); services.Configure(options => { options.FileProviders.Add(new EmbeddedFileProvider(Assembly.Load(“App”))); options.FileProviders.Add(new PhysicalFileProvider(@”C:\Users\soheil\Documents\Visual Studio 2017\Projects\WebApplication5\App”)); }); } 我的解决方案 运行localhost:5000/SameTodo获取以下错误: 缺少一个或多个编译引用。 确保您的项目引用了“Microsoft.NET.Sdk.Web”,并且“PreserveCompilationContext”属性未设置为false。 堆: 找不到类型或命名空间名称’SameTodoModel’(您是否缺少using指令或程序集引用?)+ public global :: Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper […]

无法在MVC中定义自定义渲染器lambda

我想在我的MVC视图中将自定义渲染器定义为lambda,我可以在局部使用它来多次渲染相同的东西。 我打算将它存储在视图数据中。 到目前为止,我已经创建了这个扩展方法来存储渲染器: public static class HtmlHelperExtensions { public static void DefineRenderer(this HtmlHelper html, string rendererName, Action renderer) { html.ViewData[“_Renderer” + rendererName] = renderer; } } 我正在尝试在我的视图中定义渲染器,但它不起作用; 我假设我的语法已关闭。 有人能告诉我这里我做错了什么吗? 我只是希望它在调用时呈现测试段落: @Html.DefineRenderer(“AnalysisTableHeader”, () => { test paragraph @});

如何使用Razor MVC-4将JSON数据加载到SlickGrid中

我是jquery,光滑网格和razor的新手。 我已经浏览了SlickGrid示例,并且能够将静态数据加载到SlickGrid中。 现在我正在尝试将MSSQL中的JSON数据加载到我的SlickGrid中。 我在网上看到了一些例子,但我相信我错过了那些例子中没有提到的东西。 这是我的代码。 SlickGridProducts.js var grid; var columns = [ { id: “ProductID”, name: “ProductID”, field: “ProductID”, width: 50 }, { id: “ItemDesc”, name: “ItemDesc”, field: “ItemDesc”, width: 200 }, { id: “DivName”, name: “DivName”, field: “DivName”, width: 50 }, { id: “DeptDesc”, name: “DeptDesc”, field: “DeptDesc”, width: 75 }, { id: “ClassDesc”, […]

在布局页面下拉列表 – MVC

我的问题:布局页面的下拉列表。 我读过这篇文章: ASP.NET MVC Razor传递模型来布局它或多或少类似于我的问题。 在其中一篇评论中,Mattias Jakobsson写道:“但通常的解决方案是使用RenderAction在布局页面中渲染需要自己数据的部件”。 好吧,我已经用@ Html.Action()创建了布局页面,它使用db中的日期来渲染我的drop dwon列表。 一切都很完美。 但… 我有两个页面,例如:’Home’,’About’和我在布局页面的下拉列表(ddl) 如何实现当我在’家’并且我在ddl中更改选择时它刷新’主页’页面,当我在’关于’时刷新’关于’页面。 如何通过页面存储选定的ddl值? Layout.cshtml代码的一部分: . . @Html.ActionLink(@Resources.Resource.BackToIntranet, “Index”, “Home”, null, new {@class = “link link-home grid-position-left”}) @Resources.Resource.SiteTitle @Resources.Resource.LayoutHelp @Html.ActionLink(Resources.Resource.LayoutMenuItem1, “Index”, “Home”) @Html.ActionLink(Resources.Resource.LayoutMenuItem2, “Index”, “ClimaticStation”) @Html.ActionLink(Resources.Resource.LayoutMenuItem3, “Index”, “ClimaticPoint”) @Html.ActionLink(Resources.Resource.LayoutMenuItem4, “Index”, “IcewaterExchanger”) @Html.ActionLink(Resources.Resource.LayoutMenuItem5, “Index”, “Pipeline”) @Html.ActionLink(“Zestawienie”, “YearsLength”, “Pipeline”) @Html.Partial(“~/Views/Shared/Partials/LoginPartial.cshtml”) @Html.Action(“VariantsDdl”, “MyBase”) @RenderBody() . . MyBaseController.cs […]

将glyphicon-user添加到MVC ASP.NET中的TextBoxFor控件

我想在MVC C#中的textBoxFor控件的末尾显示一个glyphicon-user但是我还没有完成,在我展示的代码中(razor评论@ * * @)我试图获得的span标签glyphicon但没有成功,请你帮我 @Html.LabelFor(model => model.usuario, new { @class = “control-label col-md-2” }) @**@ @Html.TextBoxFor(model => model.usuario, new { @class = “form-control”, @placeholder = “Usuario”, @type = “text” }) @**@ @Html.ValidationMessageFor(model => model.usuario)

在PartialView中获取变量

假设我将数据传递给这样的局部视图 @Html.Partial(“_LandingPage_CaseStudiesList”, new { TrackAction = “Case Study Click”, CaseStudies = Model.CaseStudies }) 然后我如何获取部分数据? 我已经尝试了Model[“TrackAction”]和Model.TrackAction但都没有工作,我不知道还有什么可以尝试。 如果我调试代码,我可以看到属性,但只是不知道用什么来取回它们 这是我的偏爱 @{ int counter = 1; foreach (Asset caseStudy in caseStudies) { @Html.Raw(caseStudy.Name) @Html.Raw(caseStudy.Location) counter++; } } 这是我调试时得到的图像: http : //i.imgur.com/OiReWZv.gif