Tag: asp.net mvc 3

MusicStore’System.Data.Objects.ObjectSet ‘不包含’Add’的定义,也没有扩展方法’Add’接受第一个参数

我正在关注MusicStore教程我已经在tutoria的第8部分了 。 当我尝试添加ShoppingCart类时,我遇到了这个错误..我试图谷歌找到一个可能的解决方案,但未能找到一个干净的T_T ..基于我的研究我得到这个错误因为我正在使用edmx这是数据库首先而不是代码首先在教程上。 我添加了这些代码,并在Add()和Remove()上出错 namespace Project.Models { public partial class ShoppingCart { ProjectEntities db = new ProjectEntities(); string ShoppingCartId { get; set; } public const string CartSessionKey = “cart_ID”; public static ShoppingCart GetCart(HttpContextBase context) { var cart = new ShoppingCart(); cart.ShoppingCartId = cart.GetCartId(context); return cart; } // Helper method to simplify shopping cart calls […]

如何在MVC3中获取trace.axd的自定义错误页面?

我的MVC3应用程序显示403,404和500状态代码的自定义错误页面,但浏览到trace.axd会显示以下YSOD: Server Error in ‘/’ Application. Trace Error Description: Trace.axd is not enabled in the configuration file for this application. Note: Trace is never enabled when Details: To enable trace.axd, please create a tag within the configuration file located in the root directory of the current web application. This tag should then have its “enabled” […]

MVC:如何根据值更改Html.Grid行的颜色?

我想知道如何更改Html.Grid中行的颜色,如果’Completed’布尔属性等于true。 这是一个示例网格: @Html.Grid(Model.ExampleList).Columns(c => { c.For(a => string.Format(“{0:dd/MM/yyyy}”, a.DateRequested)).Named(“Date Requested”); c.For(a => a.Comment).Named(“Comment”); c.For(a => a.Completed).Named(“Completed”); }) 任何帮助将不胜感激。 谢谢。

如何正确处理子操作exception

我有一个返回PartialView的Action: [ChildActionOnly] public ActionResult TabInfo(int id, string tab) { ViewBag.Jobid = id; ViewBag.Tab = tab; var viewModel = _viewModelManager.GetViewModel(tab, id); return PartialView(string.Format(“~/Views/{0}/Index.cshtml”, tab), viewModel); } _viewModelManager从Dictionary中返回一个视图。 如果用户请求不存在的选项卡,则会抛出KeyNotFoundexception,但是,在我的视图中,我得到以下exception: Error executing child request for handler ‘System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper’ @using MyApplication.UI.Helpers.Html @model MyApplication.UI.Models.MyJobModel @{ ViewBag.Title = “Details”; } @Model.Blah … *@ HttpException occurs here — renders default error view *@ […]

MVC ValidationMessageFor不能正常工作

我认为我有以下几点: User Registration @Html.LabelFor(m => m.UsrName) @Html.TextBoxFor(m => m.UsrName) @Html.ValidationMessageFor(m => m.UsrName) @Html.LabelFor(m => m.Pwd) @Html.PasswordFor(m => m.Pwd) @Html.ValidationMessageFor(m => m.Pwd) @Html.LabelFor(m => m.ReEnterPwd) @Html.PasswordFor(m => m.ReEnterPwd) @Html.ValidationMessageFor(m => m.ReEnterPwd) Location @Html.RadioButtonFor(m => m.Location, “Loc1”) @Html.Label(“Loc1”)    @Html.RadioButtonFor(m => m.Location, “Loc2”) @Html.Label(“Loc2”) @Html.ValidationMessageFor(m => m.Location) Role @Html.RadioButtonFor(m => m.Role, “User”) @Html.Label(“User”)    @Html.RadioButtonFor(m => m.Role, […]

迭代通过站点相对路径查找文件(ASP.NET MVC 3)

我的Web应用程序(ASP.NET MVC 3)中有一个文件夹,其中包含一组图像。 我想使用foreach循环迭代文件夹以获取站点相对路径,然后我可以将其附加到图像标记。 例 @foreach(string file in ?????) { } 我该怎么做呢? 注意:我当前的foreach循环试图查看物理路径并返回此错误 Could not find a part of the path ‘C:\Content\Images\Photography\Slides\’.

MVC 3 Cascading DropDownLists

我不知道如何准确地拥有Cascading DropDownLists 我的情景是下一个: 类别有物品和物品的数量取决于企业 我希望有两个DropDownLists,您选择一个Category,当您选择第一个包含该Category中的Items时,将填充下一个DropDownLists,当您选择Item时,将显示包含每个建立的数量的表。 好的,这将是我的ActionResult public ActionResult ItemByClinic(Guid? Item_ID, Guid? Category_ID) { ViewData[“Categories”] = InventoryDb.Categories; if (Category_ID != null) { ViewBag.Category_ID = Category_ID; ViewData[“Items”] = InventoryDb.Items.Where(i => i.Category.ID == Category_ID); if (Item_ID != null) { ViewBag.Item_ID = Item_ID; ViewData[“Inventory”] = InventoryDb.Items.Single(i => i.ID == Item_ID).Inventory; } } return View(); } 然后,我会让我的两个DropDownLists应该将值发布到Item_ID和Category_ID …第一个类别然后是项目 @Html.DropDownList(“Categories”, new […]

如何将JavaScript文件的链接添加到某个ASP .NET MVC页面的标题中

如何将JavaScript文件的链接添加到某个ASP .NET MVC页面的标题中? 可以说有_Layout.cshtml和About.cshtml,我需要将一些javascript文件放到About.cshtml的标题中。 我只是指那个页面。 http://www.dotnetcurry.com/ShowArticle.aspx?ID=636 怎么做?

如何在html帮助器中使用asp.net mvc 3 razor进行内联样式

我想做这个 @Html.TextBoxFor(x => x.BackgroundColor, new { style = “width: 20px; background-color: @Model.BackgroundColor;” }) 但是它不会渲染我的Mode.Background颜色(在firebug中我只看到@ bModel.BackgroundColor“)。这可能吗?

将DisplayTemplate设置为WebGrid列

我有这个样本 @Html.DisplayFor(modelItem => item.Expires, “DateTimeToDate” ) DateTimeToDate显示模板: @model DateTime? @Html.Label(Model.HasValue ? Model.Value.ToShortDateString(): string.Empty) 柱 … grid.Column(“Expires”, @Resources.Localization.Expires, canSort: true) … 那么,我如何在webgrid列中使用DisplayTemplate? regrads。