Tag: razor

asp.net mvc @ Html.CheckBoxFor

我的表格中有复选框 我添加了我的模型 using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace CorePartners_Site2.Models { public class CareerForm { //…. public List EmploymentType { get; set; } } } public class CheckBoxes { public string Text { get; set; } public bool Checked { get; set; } } 并在我的表格中添加 @Html.CheckBoxFor(model => model.EmploymentType, new { id = “employmentType_1” […]

在Post上的模型中保留SelectList

在MVC4中: 我的模型中有以下属性用于下拉列表: public SelectList Subjects { get; set; } 我在页面加载的Index()Action中设置了Subjects属性并返回模型。 使用SelectListItems可以很好地填充下拉列表。 @Html.DropDownListFor(x => x.Subject, new SelectList(Model.Subjects, “Text”, “Text”, “Other”)) 当我提交表单时,模型中的Subjects SelectList已更改为null。 必须有一种简单的方法来持久化HttpPost。 我想我也想提交和发布这个SelectList,以及所有表单字段? 我该怎么办?

Scripts.Render使用过时的javascript文件

我的MVC4应用程序使用Scripts.Render加载一个正在加载名为“functions.js”的文件的包。 当我在浏览器中调试此应用程序时,脚本会加载,但版本已过时。 当我直接查看资源但附加?v=anytext ,脚本看起来是正确的,但如果没有附加,脚本会显示旧代码。 有没有办法强制捆绑输出正确的文件而不是陈旧的文件?

从剃刀获取控制器名称

我似乎很难得到一些应该很容易的东西。 在我看来,使用Razor,我想得到当前控制器的名称。 例如,如果我在这里: http://www.example.com/MyController/Index 如何从Razor表达式获取控制器名称MyController : @* Obviously this next line doesn’t work @Controller.Name *@ 我是MVC的新手,所以如果这是一个明显的答案,请不要攻击我。

Razor语法可防止在ActionLink中转义HTML

我有一个ASP MVC 3站点,我们正在尝试将一些样式放入动作链接中。 我希望html类似于some text some more text但我无法弄清楚如何辨别剃刀正确渲染它的 。 到目前为止我尝试了什么: @Html.ActionLink(“some text some more text”, SomeAction, SomeController); 导致链接看起来像: some text some more text @Html.ActionLink(“some text some more text”, SomeAction, SomeController); 产生如下链接: some text some more text @Html.ActionLink(“some text some more text”, SomeAction, SomeController); 导致编译错误。 思考?

如何使用razor引擎进行图像src的电子邮件模板化

我已经找到了关于如何在asp.net中使用Razor Engine用于电子邮件模板的链接 ,并且它运行良好。 但我试图在电子邮件模板中添加带有图像的徽标。 像这样的东西: EmailTemplate.cshtml (顺便说一下,这是一个强类型视图) 当我尝试在电子邮件中提交它时,似乎没有读取图像路径,它只在内容中呈现X. 我正在考虑将图像路径作为模型的一部分传递,但它似乎很奇怪。 有没有办法实现这个目标? 任何帮助将非常感激。 谢谢

获取DropDownList的选定值。 Asp.NET MVC

我正在尝试填充DropDownList并在提交表单时获取所选值: 这是我的模型: public class Book { public Book() { this.Clients = new List(); } public int Id { get; set; } public string JId { get; set; } public string Name { get; set; } public string CompanyId { get; set; } public virtual Company Company { get; set; } public virtual ICollection Clients { […]

使用下拉列表绑定枚举并在MVC C中的get动作中设置选定值#

我有一个叫做CityType的Enum public enum CityType { [Description(“Select City”)] Select = 0, [Description(“A”)] NewDelhi = 1, [Description(“B”)] Mumbai = 2, [Description(“C”)] Bangalore = 3, [Description(“D”)] Buxar = 4, [Description(“E”)] Jabalpur = 5 } 从枚举生成列表 IList list = Enum.GetValues(typeof(CityType)).Cast().Select(x => new SelectListItem(){ Text = EnumHelper.GetDescription(x), Value = ((int)x).ToString() }).ToList(); int city=0; if (userModel.HomeCity != null) city= (int)userModel.HomeCity; ViewData[“HomeCity”] […]

Html.Raw不能正常运行asp.net mvc

我有一些html存储在一个表中。 这是一些示例数据 <p><span style="font-size: small; color: #ff0000;"><span style="font-size: small;">&nbsp;<span style="font-size: large; color: #000000;">ਮਾਂ</span><br />&nbsp; <br />ਚਾਵਾਂ ਸਧਰਾਂ ਦੇ ਨਾਲ ਮਾਏ ਜੋ ਤੂੰ ਬੂਟਾ ਲਾਇਆ,<br />ਦੇ ਮਮਤਾ ਦਾ ਪਾਣੀ ਅੱਜ ਓਹ ਭਰ ਜੋਬਨ ਤੇ ਆਇਆ,<br /> 我试图在页面上显示,我正在使用asp.net mvc razor视图和使用 @Html.Raw(blog.Body) 但它不起作用。 可以有人帮忙,是什么原因。 谢谢 成员Parminder

未找到“索引”视图或其主页

我是C#MVC项目类型的新手,当我创建一个空的C#MVC项目时,我注意到以下错误: The view ‘Index’ or its master was not found or no view engine supports the searched locations. The following locations were searched: ~/Views/ControllerName/Index.aspx ~/Views/ControllerName/Index.ascx ~/Views/Shared/Index.aspx ~/Views/Shared/Index.ascx ~/Views/ControllerName/Index.cshtml ~/Views/ControllerName/Index.vbhtml ~/Views/Shared/Index.cshtml ~/Views/Shared/Index.vbhtml 我在Views文件夹下有“Index.cshtml”文件。 为什么MVC引擎不直接在Views文件夹下? 我该如何解决这个问题? 我的RouteConfig.cs内容是: routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); routes.MapRoute( name: “Default”, url: “{controller}/{action}/{id}”, defaults: new { controller = , action = “Index”, id = UrlParameter.Optional } ); […]