asp.net-mvc-2

ASP.NET MVC - How to throw a 404 page similar to that on StackOverflow

纵饮孤独 提交于 2019-12-03 06:02:48
问题 I've currently got a BaseController class that inherits from System.Web.Mvc.Controller . On that class I have the HandleError Attribute that redirects users to the "500 - Oops, we screwed up" page. This is currently working as expected. THIS WORKS <HandleError()> _ Public Class BaseController : Inherits System.Web.Mvc.Controller ''# do stuff End Class I also have my 404 pages working on a Per-ActionResult basis which is again working as expected. THIS WORKS Function Details(ByVal id As

How to reinstall MVC 2 tools for VS2010?

一个人想着一个人 提交于 2019-12-03 06:01:59
I accidentally uninstalled the Asp.Net MVC 2 Tools for Visual Studio 2010. How can I reinstall it? The MVC2 download only seems to include the VS2008 tools. Everything I've googled says that MVC 2 is included in VS2010, but a repair install didn't fix it, and MVC 2 isn't listed as a selectable component in the VS2010's add/remove components screen. You'll find VS2010ToolsMVC2.msi on your VS2010 DVD under WCU\ASPNETMVC - hopefully that will do it! 来源: https://stackoverflow.com/questions/5326793/how-to-reinstall-mvc-2-tools-for-vs2010

Technical differences between ASP.NET and Java Servlets / JSP

随声附和 提交于 2019-12-03 05:57:22
My understanding of JSP is that every JSP page on first load is compiled into a Java Servlet. Is this the same for ASPX pages (of course, not into a servlet, but whatever the ASP.NET equivilant is)? What other technical differences should I be aware of with JSP and ASP.NET (MVC 2)? JSP pages are translated into Java source code, then compiled into class files (containing Java Byte Code) for future execution. After that, they're actually JIT (Just In Time) compiled by the JVM when they are needed for execution (so they're pretty fast). It's my guess that there's a similar process for .NET

ASP.NET MVC 2 - Html.EditorFor a nullable type?

帅比萌擦擦* 提交于 2019-12-03 05:51:22
I have two editor templates: one for decimal, and one for decimal? (nullable) But when I have a nullable decimal in my model, it tries to load the normal decimal editor: <%: Html.EditorFor(model => model.SomeDecimal )%> <%: Html.EditorFor(model => model.SomeNullableDecimal )%> The first one works fine, and loads the decimal editor template. The second one also tries to load the decimal template (and fails because it is not a decimal field). The error message is: The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.Decimal'. My

ASP.NET MVC - Current Action from controller code?

只谈情不闲聊 提交于 2019-12-03 05:44:25
This is very similar to another recent question: How can I return the current action in an ASP.NET MVC view? However, I want to get the name of the current action from within controller code. So within the code of a function that's being called by an Action, I want to get a string of the name of the current Action. Is this possible? You can access the route data from within your controller class like this: var actionName = ControllerContext.RouteData.GetRequiredString("action"); Or, if "action" isn't a required part of your route, you can just index into the route data as per usual. The only

Problem creating persistent authentication cookie: ASP.NET MVC

懵懂的女人 提交于 2019-12-03 05:43:59
OK, here's my code to create an authentication cookie: // get user's role List<UserType> roles = rc.rolesRepository.GetUserRoles(rc.userLoginRepository.GetUserID(userName)); List<string> rolesList = (from r in roles select r.ToString()).ToList(); string[] rolesArr = rolesList.ToArray(); // create encryption cookie FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket( 1, userName, DateTime.Now, DateTime.Now.AddDays(90), createPersistentCookie, String.Join(";",rolesArr) //user's roles ); // add cookie to response stream string encryptedTicket = FormsAuthentication.Encrypt

ASP.NET MVC Redirect with model

蹲街弑〆低调 提交于 2019-12-03 05:15:41
I currently have a method in my controller which accepts a form collection, saves the data, and then displays the data in a 'Details' page. At the moment, the code currently looks something like: [HttpPost] public ActionResult Create(PersonModel person)<br> { if (person.IsValid()) { person.additionalData = "Person created successfully"; return View("Details", person); } } The problem is that returning the Details view in this manner retains the URL mysite/Person/Create - ideally I would like the URL to be mysite/Person/Details/IdGoesHere. Im sure this must be possible. Obviously, I could use

How to fix Child actions are not allowed to perform redirect actions, other answers does not fix

天涯浪子 提交于 2019-12-03 05:10:46
ASP.NET MVC2 view: <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcMusicStore.ViewModels.PaymentViewModel>" %> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> ... <form action="<%= Html.Action("PaymentByBankTransfer", "Checkout") %>" > <input type="submit" value="Payment by bank transfer" /> </form> CheckoutController: public ActionResult PaymentByBankTransfer() { var order = Session["Order"] as Order; ExecCommand(@"update dok set confirmed=true where order={0}", order.OrderId); return CheckoutCompleteOK();

Why it's not a good idea to pass entities as Models in MVC?

拟墨画扇 提交于 2019-12-03 05:09:36
问题 We're developing a pretty large application with MVC 2 RC2 and we've received some feedback on the way we're using the Entity Framework's Lazy Loading. We're just getting the entities in the controller and sending them as models to the Views, that is causing that the view code asks the Database for the navigation properties we are using in it. We have read about this and it appears is not a good design, but we were wondering why? Can you help us understand this design problem? Thanks! 回答1:

Asp.Net MVC 2 Html.TextBoxFor Best way to specify a format string for a DateTime property of model

依然范特西╮ 提交于 2019-12-03 04:59:43
问题 As the question title explains, what is the best way to specify a format which my Views use when displaying values of a DateTime property via the Html.TextboxFor method. The default display includes the Date and Time where I really only want the Date displayed. Thanks 回答1: In your model definition add the DisplayFormatAttribute to the DateTime property: [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")] public DateTime Date { get; set; } Then in your View call: