asp.net-mvc-3

MVC3 Routing Basics

蹲街弑〆低调 提交于 2020-01-22 13:12:47
问题 I am learning MVC routing. Hope my question doesn't look silly, and please help :) public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); Msdn reference says it takes a String, String, Object, so I try to make a small change (added a "my" in front

Unable to setup MiniProfiler w/ Enity Framework 4.0 (Not code first)

北城以北 提交于 2020-01-22 13:05:23
问题 I installed MiniProfiler and MiniProfiler.EF in my project via nuget. Before using MiniProfiler I would open a connection using this in my model repository: public class NotificationRepository { private CBNotificationModel.CB_NotificationEntities db; public NotificationRepository() { db = new CB_NotificationEntities(); } public NotificationContact GetNotificationContacts() { return db.NotificationContacts.ToList(); } } To use mini profiler I created: public static class ConnectionHelper {

Unable to setup MiniProfiler w/ Enity Framework 4.0 (Not code first)

若如初见. 提交于 2020-01-22 13:02:26
问题 I installed MiniProfiler and MiniProfiler.EF in my project via nuget. Before using MiniProfiler I would open a connection using this in my model repository: public class NotificationRepository { private CBNotificationModel.CB_NotificationEntities db; public NotificationRepository() { db = new CB_NotificationEntities(); } public NotificationContact GetNotificationContacts() { return db.NotificationContacts.ToList(); } } To use mini profiler I created: public static class ConnectionHelper {

ASP.NET MVC 3 Remote validation to allow original value

谁说胖子不能爱 提交于 2020-01-22 10:01:48
问题 I have a Remote attribute on the email property of my User model. When I create a new user, it works create and tells the users that an e-mail is already in use. Now I'm having a problem in my editing form (if the user wants to updates values). It tells the user that his/her e-mail is already in use, I don't want it to give that message when the e-mail that's in use is the one that's registered to the user. How can I tweak the Remote attribute to behave? 回答1: I figured it out. In my view, I

ASP.NET MVC Determine mime type by file/file path

南楼画角 提交于 2020-01-22 09:27:08
问题 I am using ASP.NET MVC 3. The application is targeting .net 4.0. I was trying to pass a virtual path as argument to my controller's action and return the file without reviewing the actual physical path on the server and providing basic Authorization. Unfortunately I was unable to find a suitable overload for File method to generate the appropriate ActionResult. I am stuck at determining mime type for the file. I've found a couple of solutions for determining mime-types by file name, but none

ASP.NET MVC4 CustomErrors DefaultRedirect Ignored

∥☆過路亽.° 提交于 2020-01-22 07:20:11
问题 I have an MVC 4 app, using a custom HandleErrorAttribute to handle only custom exceptions. I would like to intercept the default 404 and other non-500 error pages and replace them with something more attractive. To that end, I added the following to my Web.config: <system.web> <customErrors mode="On" defaultRedirect="~/Error/Index" /> ... </ system.web> I have an Error controller with an Index method and corresponding view, but still I get the default 404 error page. I have also tried setting

ASP.NET MVC4 CustomErrors DefaultRedirect Ignored

扶醉桌前 提交于 2020-01-22 07:20:08
问题 I have an MVC 4 app, using a custom HandleErrorAttribute to handle only custom exceptions. I would like to intercept the default 404 and other non-500 error pages and replace them with something more attractive. To that end, I added the following to my Web.config: <system.web> <customErrors mode="On" defaultRedirect="~/Error/Index" /> ... </ system.web> I have an Error controller with an Index method and corresponding view, but still I get the default 404 error page. I have also tried setting

ASP.NET MVC3 Razor - create view from a string?

让人想犯罪 __ 提交于 2020-01-21 09:14:10
问题 Is there a convenient way to return a view from a string instead of having to come from a file on disk? I've implemented a custom VirtualPathProvider that handles retrieving views from a database, but I don't always want the view to be stored in the database. Update 2-15-2011 I stumbled across a very nice open source component that simplifies the process of compiling Razor views in code.I've replaced much of the Virtual Path Provider code with this component, and it's working incredibly well.

How to generate a URL for ASP.NET MVC action, including hostname and port? [duplicate]

不问归期 提交于 2020-01-21 01:33:29
问题 This question already has answers here : How do I find the absolute url of an action in ASP.NET MVC? (9 answers) Closed 5 years ago . My current request is: http://www.mofeng.com:4355/ I want display an action url in asp.net view layer, url is like this(full url, including http://protocol + hostname + port + controllerName + actionName ): http://www.mofeng.com:4355/controllerX/actionY 回答1: Url.Action("Action", "Controller", null, Request.Url.Scheme); How to include the following in the Form

HTML.HiddenFor value set

*爱你&永不变心* 提交于 2020-01-20 15:22:06
问题 @Html.HiddenFor(model => model.title, new { id= "natureOfVisitField", @value = '@Model.title'}) it doesen't work! how to set the value? 回答1: You shouldn't need to set the value in the attributes parameter. MVC should automatically bind it for you. @Html.HiddenFor(model => model.title, new { id= "natureOfVisitField" }) 回答2: For setting value in hidden field do in the following way: @Html.HiddenFor(model => model.title, new { id= "natureOfVisitField", Value = @Model.title}) It will work 回答3: