Tag: asp.net mvc 3

为每个用户mvc配置输出缓存

我有一个用户特定的仪表板。 仪表板每天只会更改,我想使用MVC’s OutputCache 。 有没有办法配置每个用户的缓存,并在请求是新的一天到期? 我研究了这个,发现你可以扩展OutputCache属性来动态设置你的持续时间,但是如何为每个用户配置? 提前致谢

MVC 3 – 如何实现服务层,我需要存储库吗?

我目前正在使用EF Code First,SQL CE和Ninject构建我的第一个MVC 3应用程序。 我已经阅读了很多关于使用存储库,工作单元和服务层的信息。 我想我已经完成了基础知识,并且我已经完成了自己的实现。 这是我目前的设置: 实体 public class Entity { public DateTime CreatedDate { get; set; } public Entity() { CreatedDate = DateTime.Now; } } public class Profile : Entity { [Key] public Guid UserId { get; set; } public string ProfileName { get; set; } public virtual ICollection Photos { get; […]

如何在C#中的for循环的每次迭代之间添加一些延迟?

我正在使用C#编写ASP.NET MVC3。 我想在for循环的每次迭代之间添加一些延迟。 for(int i=0; i<5; i++) { //some code //add delay here } 那我怎么能这样做?

如何在两个SelectListItem列表之间使用Except()

我有两个类型IEnumerable 我需要创建一个新的IEnumerable ,其中第一个列表的元素在第二个列表中不存在。 我怎样才能做到这一点? 我尝试使用Except()但没有结果…… 示例代码: IEnumerable SelectListItemA = ….; IEnumerable SelectListItemB = ….; IEnumerable Except = SelectListItemA.Except(SelectListItemB);

如何使用method =“post”从表单中获取数据? 如何在我的控制器中请求数据?

我试图从我的HTML代码中获取数据,如“acquringCode”,“cardAcceptor”和“merchantId”。 我无法想象如何在我的控制器中获取该数据。 我知道它的request.form。 我相信我做错了。 有没有更简单的方法让我通过函数传递对象或每个名称作为参数? HTML $(document).ready(function () { $(“#SavetreventLocationLookupAddButton”).click(function () { $(“#addSaveTreventLocationLookup”).submit(); }); }); 添加Trevent位置查找 <form id="addSaveTreventLocationLookup" method="post" action="”> Trevent Location Lookup Detail Acquiring Institution Identification Code: Card Acceptor Identification Code: Merchant Id: Add Cancel 位指示 [HttpPost] [AuthorizeAttribute(AdminRoles = “AddTreventLocationLookup”)] public ActionResult AddSaveTreventLocationLookup() { try { string acquiringInstitutionIdentificationCode; //= Request.Form[“AcquiringInstitutionIdentificationCode”] ?? string.Empty; string cardAcceptorIdentificationCode;// […]

从局部视图中获取当前控制器和操作

我正在使用以下内容获取asp.net MVC3中的当前控制器和操作: var currentAction = routeData.GetRequiredString(“action”); var currentController = routeData.GetRequiredString(“controller”); 这非常有效。 但是,如果我从我的布局调用的局部视图中调用它,则“Layout”将作为当前控制器返回。 这当然是正确的行为,但有没有办法访问父控制器的名称? 编辑以进一步说明: 我在_Layout.cshtml中调用我的菜单控制器和部分视图: @Html.Action(“Menu”, “Layout”) 然后从该菜单局部视图中,我调用返回当前操作和控制器的代码。

使用Entity Framework的Model上的DisplayName

我有一个代码如下: public class MyModel { [Required] [Display(Name = “labelForName”, ResourceType = typeof(Resources.Resources))] public string name{ get; set; } } 问题是在生成的Entity Framework模型类中添加了属性Display和Required。 我知道我可以使用Partial添加function但是如何将属性添加到将使用ORM擦除和更新的类?

在ASP.NET MVC应用程序中锁定一个全局对象时是否可能出现死锁?

对于锁定,我使用的是一个对我的应用程序来说是全局的静态对象: public class MvcApplication : System.Web.HttpApplication { public static readonly object AppLock = new object(); … } 用它来锁定代码: lock(MvcApplication.AppLock) { … } 我们暂时不要考虑性能影响。 我能100%确定在这种情况下我会避免死锁吗?

HTML Agility pack:解析href标记

我如何有效地解析href属性值: 7 D. Kulikov D 0 0 0 […] 我有兴趣拥有玩家ID,这是: 8475179这是我到目前为止的代码: // Iterate all rows (players) for (int i = 1; i < rows.Count; ++i) { HtmlNodeCollection cols = rows[i].SelectNodes(".//td"); // new player Dim_Player player = new Dim_Player(); // Iterate all columns in this row for (int j = 1; j < 6; ++j) { […]

无法加载文件或程序集’System.Web.WebPages’

我之前遇到过这个问题,但我需要做的就是清理和重建项目。 现在这似乎不再起作用了。 当我启动我的Asp.Net MVC3项目调试器时,该站点在我的浏览器中打开。 我得到了这个错误,而不是在浏览器中显示第一页 Parser Error Message: Could not load file or assembly ‘System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified. Source Error: Line 31: Line 32: Line 33: Line 34: Line 35: 我似乎无法弄清楚如何解决这个问题。 任何的想法?