Tag: razor

在Html.Textbox上设置必需的属性

我正在寻找创build一个Bootstrap风格的文本框,具体来说,基于下面的确切例子: <input class="span3" type="email" required> 以下是我到目前为止: @Html.TextBox("CustomerEmail", null, new { @class = "input-xlarge", type = "email", required = "required" }) 但是, required = "required"显然不会仅仅required返回。 所以,我的问题是,当使用Html.Textbox时,有没有什么办法可以像上面第一个例子那样强制它返回?

MVC Razor HTML助手语法:Html.Hidden对象参数中的Viewbag

我正在尝试添加一个对象到我的Html.Hidden HTML助手,但我不能得到正确的语法。 语法1: @Html.Hidden("hiddenDate", ViewBag.myDate.ToString("dd.MM.yyyy")) 结果在运行时错误,它不能解决在视图中@ Html.Hidden。 语法2: @Html.Hidden("hiddenDate", new { String = ViewBag.myDate.ToString("dd.MM.yyyy")}) 设置值=“{String = 16.04.2012}” 我想获得只有“16.04.2012”的价值,但几次语法调整后没有成功

本地主机不工作在铬和Firefox

我正在做一个使用Visual Studio 2010(MVC3 Razor)和Windows 7的Web项目。 我的默认浏览器是IE。 当我运行该项目时,网站的工作是完全与url HTTP://本地主机:49824 / 当我复制相同的url,并尝试运行在Chrome或Firefox的网站,它显示我以下错误。 错误 The requested URL could not be retrieved The following error was encountered while trying to retrieve the URL: http://localhost:49824/ Connection to 127.0.0.1 failed. The system returned: (111) Connection refused The remote host or network may be down. Please try the request again. Your cache […]

Razor视图与ASPX.Master页面可能吗?

是否有可能保持我现有的.master页面,并使用一个新的ASP.NET MVC 3 Razor视图? 我试过这个: @{ LayoutPage = "~/Views/Shared/Site.master"; } 它给了我这个错误消息: 文件“〜/ Views / Shared / Site.master”无法呈现,因为它不存在或不是有效的页面。

MVC SelectList在文本字段中组合多个列

我如何生成一个select列表,其中的文本字段,由两个或两个以上的文本列组成,例如:我的数据库中有一个描述和比率字段,我想结合这些显示: Large–£200 Medium–£150 Small–£100 控制器代码是: var stands = db.Stands.Where(s => s.ExhibitorID == null).ToList(); ViewBag.StandID = new SelectList(stands,"StandID", "Description" + "– £" + "Rate"); …我的观点是(目前): <div class="editor-field"> @Html.DropDownList("StandID", "–Select–") </div> …但是“描述”+“ – £”+“比率”); 将不会运行: DataBinding:'System.Data.Entity.DynamicProxies.Stand_63F8C9F623B3C0E57D3008A57081AFCD9C39E1A6B79B0380B60840F1EFAE9DB4'不包含名称为'Description – £Rate'的属性。 谢谢你的帮助, 标记

将字节数组转换为图像并在剃刀视图中显示

我使用EF 4.1 Code First ,为了简单起见,假设我有以下实体类: public class Person { public int Id { get; set; } public string Name { get; set; } public Byte[] Image { get; set; } } 我已经设法创build一个工作的创build视图,允许添加一个Person对象到数据库中。 但是,当我来显示一个人的细节,我被卡在显示图像 。 在Googlesearch了好几个小时后,我有以下几点: // To convert the Byte Array to the author Image public FileContentResult getImg(int id) { byte[] byteArray = DbContext.Persons.Find(id).Image; return […]

如何用剃刀视图引擎简洁地创build可选的HTML属性?

我正在寻找一种方式来编写下面的代码行(可能是5)的代码。 我想我可以做所选类的相同的东西,但这个剃刀的语法看起来不漂亮。 <ul> @foreach (var mi in Model.MenuItems) { <li@(mi.Selected?" class=\"selected\"":null)> @if (string.IsNullOrEmpty(mi.Title)) { <a href="@mi.Href">@mi.Text</a> } else { <a href="@mi.Href" title="@mi.Title">@mi.Text</a> } </li> } </ul>

为什么不能在MVC4 Razor布局文件中识别@Scripts和@Styles命令?

下面的MVC4 Razor布局文件加载了在Bundle.config中创build的几个脚本和css包。 <!DOCTYPE html> <html class="no-js" lang="en"> <head> <meta charset="utf-8" /> <title>XXX Beta</title> @Scripts.Render( "~/bundles/bundle_jquery", "~/bundles/bundle_modernizr", "~/bundles/bundle_foundation", "~/bundles/bundle_jhs") @Styles.Render( "~/Content/bundle_foundation", "~/Content/bundle_jhs") @RenderSection("pageHeadContent", false) </head> <body> <div id="bodyContainer"> @Html.Partial("Partial/_header") <div id="contentContainer"> <div id="mainContentContainer"> <div id="sidebarContainer"> @RenderSection("sidebarContent", required: true) </div> @RenderBody() </div> <div class="clearBoth"> </div> </div> @Html.Partial("Partial/_footer") </div> </body> </html> 页面呈现时出现以下错误。 出于某种原因,@Scripts和@Styles命令不被识别。 如果我在文件中键入“@Scripts”,则Intellisense不显示/显示该命令。 该项目确实引用了在Bundle.config中使用的System.Web.Optimization。 什么可能导致@Scripts和@Styles命令不被识别? “/”应用程序中的服务器错误。 编译错误 […]

如何在运行时编译cshtml

我相信我读了某个地方有一个项目文件中的一个设置,将允许您在构buildVisual Studio项目时编译.cshtml文件。 刚开始使用MVC/Razor/Query Mobile,当我在.cshtml文件中的代码块中出现错误时,我正在烦恼“错误加载页面”

在razor文件中的@functions代码块是做什么的,什么时候(如果曾经)我应该使用它?

虽然看着我从Orchard CMS图库下载的主题,但是我注意到一个Layout.cshtml文件在这个文件的顶部有这个代码块: @functions { // To support the layout classifaction below. Implementing as a razor function because we can, could otherwise be a Func<string[], string, string> in the code block following. string CalcuClassify(string[] zoneNames, string classNamePrefix) { var zoneCounter = 0; var zoneNumsFilled = string.Join("", zoneNames.Select(zoneName => { ++zoneCounter; return Model[zoneName] != null ? zoneCounter.ToString() […]