asp.net-mvc-2

Restrict Area to a given role

旧城冷巷雨未停 提交于 2019-12-05 16:43:12
I have an area setup in MVC2, called Admin/ , which I want I only want Users who belong to the role "admins" to have access. I know I can decorate each of the methods with [Authorize(Roles="admins")] , but this seems tedious when your talking about multiple controllers with multiple actions. Is there an better and cleaner way? You could define a base controller decorated with this attribute that all controllers in the area derive from. 来源: https://stackoverflow.com/questions/3291385/restrict-area-to-a-given-role

Add CSS references to page's <head> from a partial view

夙愿已清 提交于 2019-12-05 16:23:43
问题 Is there a way to add CSS references to a page from a partial view, and have them render in the page's <head> (as required by the HTML 4.01 spec)? 回答1: If you're using MVC3 & Razor, the best way to add per-page items to your section is to: 1) Call RenderSection() from within your layout page 2) Declare a corresponding section within your child pages: /Views/Shared/_Layout.cshtml: <head> <!-- ... Rest of your head section here ... -> @RenderSection("HeadArea") </head> /Views/Entries/Index

asp.net mvc datatable

China☆狼群 提交于 2019-12-05 16:21:15
How can I pass datatable to the mvc view How would I iterate over it in the view In your controller: public ActionResult Index() { DataTable dt = new DataTable(); return View(dt); } In your View: Just make your model of type DataTable Inherits="System.Web.Mvc.ViewPage<System.Data.DataTable>" To iterate over it: <% foreach (System.Data.DataRow row in Model.Rows) { %> <%= row["column"].ToString(); %> <%}%> 来源: https://stackoverflow.com/questions/2794831/asp-net-mvc-datatable

Creating a dropdownlist from your controller or view model

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 16:08:04
How would I create a SelectList in my controller and pass it to my view? I need to give the "-- Select --" option a value of 0. I'm responding to the replies that I got from Jeremey of Fluent Validation . This is what I currently have. My view model: [Validator(typeof(CreateCategoryViewModelValidator))] public class CreateCategoryViewModel { public CreateCategoryViewModel() { IsActive = true; } public string Name { get; set; } public string Description { get; set; } public string MetaKeywords { get; set; } public string MetaDescription { get; set; } public bool IsActive { get; set; } public

How to change width of html.DropDownListFor()

拈花ヽ惹草 提交于 2019-12-05 15:24:03
问题 I have small design question about html.DropDownListFor() How can I change width of html.DropDownListFor() ?? For example by css. Thanks for answers 回答1: Have you tried Html.DropDownListFor( new {width:"100"}) or Html.DropDownListFor( new {@class:"longDropdownList"}) EDIT <style> .MakeWide { width: 200px; } </style> <%= Html.DropDownListFor(x => x.Name, new SelectList(new List<string>()), new { @class = "MakeWide" })%> 回答2: @Html.DropDownListFor(x => x.Name, new SelectList(new List<string>())

hide columns dynamically in rdlc report

Deadly 提交于 2019-12-05 15:15:47
问题 How we can hide columns dynamically in rdlc reports in MVC 2? Is it is possible using external parameters? How we can programmatically control the visibility of columns in rdlc reports? 回答1: You don't want to use the Hidden property, you actually want to select the column, Right Click and select Column Visibility . Once in here you can use an expression to set the visibility based on a parameter, something like this: = iif(Parameters!column_visible.Value = 1, false, true) Hidden doesn't work

Localizing Error Messages In ASP.NET MVC 2 (Default Validation Attributes)

不羁的心 提交于 2019-12-05 14:54:36
i'm working on a multi language website and i want to localize the validation error messages for most of the ValidationAttribute such as [Requried] I know it can be done as Phil Haack have shown in this article . [Required(ErrorMessageResourceType = typeof(Resources), ErrorMessageResourceName = "Required")] but i want to to customize the error message the way i did with my custom Validation Attributes in here : [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public sealed class ValidateminRequiredNonalphanumericCharactersAttribute :

How do you create an HtmlHelper outside of a view in ASP.NET MVC 2.0?

你离开我真会死。 提交于 2019-12-05 14:54:18
We are in the process of upgrading an ASP.NET MVC 1.0 application to the 2.0 release and some of the code requires the use of LinkExtensions which require an HtmlHelper to render. While we know that some of the code doesn't follow the MVC model correctly and are in the process of recoding as needed, we need something to work so get the application to build. Here is the current syntax that we have that works under ASP.NET MVC 1.0: public static HtmlHelper GetHtmlHelper(ControllerContext context) { return new HtmlHelper(new ViewContext(context, new WebFormView("HtmlHelperView"), new

Upgrade MVC 2 to MVC 3 issues with views

泪湿孤枕 提交于 2019-12-05 14:37:05
I'm attempting to upgrade my existing ASP.net MVC 2 web application to MVC 3 so I can use the goodness that is the Razor Viewengine and other said improvements. After using the converter to convert my app from mvc2 to mvc3 I'm having issues with my strongly typed views. As an example here we have a view user control that is strongly typed to the class Profile <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Profile>" %> During compilation I'm getting Compiler Error Message: CS1061: 'object' does not contain a definition for 'folio' and no extension method 'folio' accepting a

Caching Data .Net 4.0 (Asp.NET)

强颜欢笑 提交于 2019-12-05 14:29:52
Can anybody explane me what is " CacheSpecificEviction " in detail and how to avoid it? I am geting this in CacheEntryRemovedArguments.RemovedReason . CacheSpecificEviction as reason for removing cache entry means "the item was removed, because the cache provider's eviction policy determined it should be removed" - I know, it is pretty unspecific, but it hardly can be more specific, because of many possible cache-engine implementations and their different eviction policies (often configurable, for example in AppFabric Cache aka Velocity). In generel, eviction means "ok, there are risk of