asp.net-mvc-2

MVC MapPageRoute and ActionLink

我们两清 提交于 2019-11-30 08:20:19
问题 I have created a page route so I can integrate my MVC application with a few WebForms pages that exist in my project: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // register the report routes routes.MapPageRoute("ReportTest", "reports/test", "~/WebForms/Test.aspx" ); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter

Code First adding to collections? How to use Code First with repositories?

风格不统一 提交于 2019-11-30 08:14:02
问题 EDIT: This happen only on larger scale projects with repositories. Is there anybody using EF4 with CodeFirst approach and using repositories? Please advise me. Hi. Im currently working with EF4 CodeFirst Classes. In my test project I got two classes, Author and Book (author got books). What I'm trying to do is that I have a AddBook in my Author class, but that wont seem to work like I can't Add it to the collection.. here are my classes and two different exceptions. public class Book { public

Radio Button generates duplicate HTML id-s

依然范特西╮ 提交于 2019-11-30 07:52:34
It seems that the default ASP.NET MVC2 Html helper generates duplicate HTML IDs when using code like this (EditorTemplates/UserType.ascx): <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<UserType>" %> <%: Html.RadioButton("", UserType.Primary, Model == UserType.Primary) %> <%: Html.RadioButton("", UserType.Standard, Model == UserType.Standard) %> <%: Html.RadioButton("", UserType.ReadOnly, Model == UserType.ReadOnly) %> The HTML it produces is: <input checked="checked" id="UserType" name="UserType" type="radio" value="Primary" /> <input id="UserType" name="UserType" type=

Using MVC's AuthorizeAttribute with multiple groups of Roles?

[亡魂溺海] 提交于 2019-11-30 07:41:23
What I want to do is a two-level role check on an action handler. For example, Require that the users is in at least one of the following groups: SysAdmins, Managers AND in at least one of the following groups: HR, Payroll, Executive. Initial guess was that this might be the way to do this but I don't think it is: [Authorize(Role="SysAdmins,Managers")] [Authorize(Role="HR,Payroll,Executive")] public ActionResult SomeAction() { [...] } Do I need to role my own custom Attribute to take in Role1 and Role2 or something like that? Or is there an easier/better way to do this? You'll need your own

Render View programmatically into a string

扶醉桌前 提交于 2019-11-30 07:31:11
I would like to get the html code a view would generate in a string, modify it in my controller, then add it to my JsonResult. I found code that would do what i'm talking about from a partial. I would like to do it from an aspx View though. -- Extra explanation: Let's say I have a page Frame.aspx that /Controller/Frame will return I would like to get my hand on the response before it out so I can to wrap it with jsonp. I do not wish to edit the return result in code every time, this is why I want to load the view programmatically. /Controller/Frame currently returns Frame.aspx's content: <html

Validation messages are displayed when page load

孤人 提交于 2019-11-30 07:01:11
I have a problem with validation in ASP.NET MVC 2.0. I use the same Action in Controller to perform user request. For example: public ActionResult Index(ReportModel model) { if (!model.IsInitialDisplay && ModelState.IsValid) { model.Result = service.GetResult(model); } return View(model); } In the ReportModel, I define a flag IsInitialDisplay to determine whether the page is initial displayed or not: public class ReportModel { [Required(ErrorMessage = "*")] public string Criteria { get; set; } public bool IsInitialDisplay { get; set; } public ReportResult Result { get; set; } public

.NET 4 MVC 2 Validation with annotations warning instead of error

落花浮王杯 提交于 2019-11-30 06:58:20
I am using .NET 4 with MVC 2 for validating with Annotations. Is there a (simple) solution for giving back a warning instead of the error ? So that I am able to get a green or yellow box with a message like "you should not use this content, but you may". Big thanks in advance! :) EDIT: Please observe that I am already able to throw out errors via ErrorMessage but I additionally want something like WarningMessage or InfoMessage so that the user only gets a warning but might proceed. Is there a solution for this? The Pseudocode would be: (Please note the "pseudo", because WarningMessage is

Foreach on IEnumerable property and CheckBoxFor in ASP.Net MVC

感情迁移 提交于 2019-11-30 06:56:42
I believe this question applies to any of the "For" Html helpers, but my specific problem is using CheckBoxFor... I have a model that is of type IEnumerable, where rights is a simple POCO. This model is actually a property of a bigger model that I created an EditorTemplate for. Here is the bigger picture of my model: public class bigmodel { public string Title {get; set;} public string Description {get; set;} [UIHint("ListRights")] public IEnumerable<rights> Rights {get;set;} } public class rights { public bool HasAccess {get; set;} public string Description {get;set;} } I created an

ASP.NET MVC - Uploading an image to Amazon S3

孤街醉人 提交于 2019-11-30 06:56:08
I have my image from Request.Files[0]. Now, how do I upload this image to S3? I see that in the AWS .NET API you have to specify ContentBody when putting an object which is a string. How would I get the content body of my file? var file = Request.Files[0]; PutObjectRequest request = new PutObjectRequest(); request.BucketName = "mybucket" request.ContentType = contentType; request.Key = key; request.InputStream = file.InputStream; s3Client.PutObject(request); Slightly more detail with how to use folders and to grant all users read-only access. Html: C# HttpPostedFileBase file = Request.Files[0]

IIS7.5 ASP.NET MVC users hitting strange URLs: /(F(1xe9eXIxPz

大憨熊 提交于 2019-11-30 06:01:13
问题 We are getting reports from a small number of users that they are ending up on very strange paths in our web app, of the form: https://www.example.com/(F(1xe9eXIxPzMALrZu6xd_6LBxDDlJI3lH2lkSvREZZKCfPBH20SF5EcNql6uXvyBVLgiNZshp9vXxaEzuLa5zm8c4ruux6gqu3B90eXGNmKDypu-wKR4OW_GwQctfjCdoxFYcDlLwglfE6rICL3JGkxtq4jgxggiQgJopKZGzLJ_PF2lHY7NqXya8eDshkP9o8QFDad47U54TMsxEwKCki2xPV9d9VxxjmDhNg7aQb38X_OTxHtf9I7AxiccanJf4m0bo0ceEJ70Mv20XYaMSlA2))/some/path (Note: i've changed random chars in that in case