asp.net-mvc-2

Donut Caching ASP.NET MVC2

喜你入骨 提交于 2019-12-05 21:17:27
问题 Is there a possibility to do Donut Caching with MVC2? Even with a lot of research I was not able to find a working solution. 回答1: Donut caching does not work with ASP.NET MVC 2, see http://forums.asp.net/t/1521502.aspx : Supporting donut caching would require view engines to be able to send an array consisting of literal text + callbacks to the writer. This is a major plumbing change and is not something that will be included in v2 of the product. 回答2: Not Supported != Not Possible http:/

Asp.net mvc 2 .net 4.0 error when View model type is Tuple with more than 4 items

馋奶兔 提交于 2019-12-05 21:15:27
When I create strongly typed View in Asp.net mvc 2, .net 4.0 with model type Tuple I get error when Tuple have more than 4 items example 1: type of view is Tuple<string, string, string, string> (4-tuple) and everything works fine view: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/WebUI.Master" Inherits="System.Web.Mvc.ViewPage<Tuple<string, string, string, string>>" %> controller: var tuple = Tuple.Create("a", "b", "c", "d"); return View(tuple); example 2: type of view is Tuple<string, string, string, string, string> (5-tuple) and I have this error: Compiler Error Message:

.NET MVC : Pass back complex object or list array from view to controller

落花浮王杯 提交于 2019-12-05 19:48:39
I want to pass a list array from the View to the controller on submission of the form. I can pass back simple values by using the Html.hidden() function. But how does one pass back a complex object or a List array You can either use Json or look into the following example http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/ You can pass back a list within a view model using Html.hidden for each element of a list. The list property in your view model will be re-constructed as long as you process the list elements using a for loop in your view ( foreach

ASP.NET Request Validation Exception Even When Validation Is Disabled

故事扮演 提交于 2019-12-05 19:00:36
I am using ASP.NET MVC 2, .NET 4.0. I have a controller that disables request validation: [AcceptVerbs("POST")] [ValidateInput(false)] public ActionResult Add(string userId, FormCollection formValues) { //... } and I still get a HttpRequestValidationException when a POST contains HTML: System.Web.HttpRequestValidationException (0x80004005): A potentially dangerous Request.Form value was detected from the client (ThisWeek=""). at System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection) at System.Web.HttpRequest

Not able to access GetModelStateValue in custom control in asp.net mvc2

故事扮演 提交于 2019-12-05 18:40:48
I am trying to write a custom control for text box control where in would like to generate the control based on some input attributes , I am not able to access GetModelStateValue in my custom control. How do i do this ? You won't be able to access it as that method is marked as an internal method. The best you can do is just duplicate the MVC source code and place that method somewhere where you can access it. You can use the following. Note you will need to pass in the htmlHelper object to access the ViewData. static object GetModelStateValue(HtmlHelper htmlHelper, string key, Type

EF4: how to use a generic repository pattern ?

99封情书 提交于 2019-12-05 18:39:10
I'm trying to streamline my existing repos by using a generic repo I can subclass from. The problem is that I can't figure out how to write a few of my base class methods. I currently have: public interface IRepository<T> : IDisposable where T : class { IQueryable<T> GetAll(); T GetSingle(int id); T GetSingle(string slug); void Save(T entity); } public class HGRepository<T> : IRepository<T> where T : class { protected HGEntities _siteDB; protected IObjectSet<T> _objectSet; public HGRepository(HGEntities context) { _siteDB = context; _objectSet = _siteDB.CreateObjectSet<T>(); } public

ASP.NET MVC: Why can't I set ShowForEdit model metadata with an attribute?

随声附和 提交于 2019-12-05 18:29:29
Why can't I set ShowForEdit model metadata with an attribute? It seems that the only attribute provided to alter this is [ScaffoldColumn] , which sets both ShowForEdit and ShowForDisplay , which is not what I want to do. I want to be able to annotate the two separately from on my model. John Farrell Because it is not supported out of the box. AFAIK the reason is because the dataannotations attribute that support this functionality are in .net 4.0 and in order to make MVC 3.5 and 4.0 compatible they had to be excluded. The easiest way to fix this is to have to implement your own Edit/Show

What's the recommended way to report model state and application errors to client?

天大地大妈咪最大 提交于 2019-12-05 18:28:00
I'm wondering what the best practice is in reporting back to the browser about application or model state errors that would be displayed to the user. Can you throw an exception and handle it in the error handler of the jquery post? For example, consider this method: [HandlerErrorWithAjaxFilter, HttpPost] public ActionResult RetrievePassword(string email) { User user = _userRepository.GetByEmail(email); if (user == null) throw new ClientException("The email you entered does not exist in our system. Please enter the email address you used to sign up."); string randomString = SecurityHelper

Why isn't MarkdownSharp encoding my HTML?

≡放荡痞女 提交于 2019-12-05 18:14:36
问题 In my mind, one of the bigger goals of Markdown is to prevent the user from typing potentially malformed HTML directly. Well that isn't exactly working for me in MarkdownSharp. This example works properly when you have the extra line break immediately after "abc"... But when that line break isn't there, I think it should still be HtmlEncoded, but that isn't happening here... Behind the scenes, the rendered markup is coming from an iframe. And this is the code behind it... <% var md = new

Antiforgery token exception only when debugger is run

时光毁灭记忆、已成空白 提交于 2019-12-05 18:14:29
I have an mvc2 app which is serving content through iframes. The iframed page is simply a form. It has a request validation token. Everything works well cross domain until a developer uses the Visual Studio 2005 debugger. As soon as they do, I get the following error details. Exception: System.Web.Mvc.HttpAntiForgeryException : A required anti-forgery token was not supplied or was invalid. Stack Trace: at System.Web.Mvc.ValidateAntiForgeryTokenAttribute.OnAuthorization(AuthorizationContext filterContext) at System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext