asp.net-mvc-2

MVC Back button issue

淺唱寂寞╮ 提交于 2019-12-01 01:53:37
I have an action method that I need to execute when the back button is clicked. I've done this before by disabling the cache in my action method (Response.Cache.SetCacheability(HttpCacheability.NoCache). This isn't working for a different action method. For some reason when i disable the cache and hit the back button to trigger my action method the page expires. Any ideas on what the issue may be? There is no way to know, on the server side, if the page request was the result of the back button or not. More than likely, the previous request was a post rather than a get, and the post requires

Render Partial of same name as parent View - Crashes WebDev.WebServer40.exe

天大地大妈咪最大 提交于 2019-12-01 01:36:56
I'm wondering whether other people are having this same issue or whether it's just me ! Given I have a View Purchases.aspx and a partial view Purchases.ascx : Within Purchases.aspx if I do: Html.RenderPartial("Purchases") then WebDev.WebServer40.exe basically closes. I'm guessing that this is caused by a Stack Overflow because RenderPartial cannot determine what it's supposed to render (.aspx or .ascx). Is this a bug, is it a defined behaviour, or is it just happening for me? It is defined behaviour since the ViewLocationFormats and PartialViewLocationFormats are defined as follows and an aspx

Having trouble with a simple MVC route

扶醉桌前 提交于 2019-12-01 01:27:10
Having some trouble with some routes. I don't fully understand the MVC routing system so bear with me. I've got two controllers, Products and Home (with more to come!). I want to have the views within the Home controller accessible without having to type Home in the url. Essentially I want to turn www.example.com/home/about into www.example.com/about, however I still want to preserve the www.example.com/products. Here's what I have so far. routes.MapRoute( "Home", "{action}", new { controller = "Home" } ); routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "home",

MVC 2 UpdateModel on Interface, Should ModelBinderAttribute be ignored?

佐手、 提交于 2019-12-01 01:20:40
I have forms posting data from instances of a particular abstract class: public abstract class IRestriction { public string Name {get; set;} public abstract IModelBinder GetBinder(); } The concrete type and PartialView are determined at runtime: IRestriction restriction = (IRestriction)Activator.CreateInstance(Type.GetType(restriction.restriction_class)); The appropriate partial view is then rendered correctly. When the form is sent back the type is inferred correctly and activated the same way. However, I haven't been able to get UpdateModel to bind to the concrete implementation. How do I

In ASP.NET MVC 2 - How do I get Route Values into my navigation controller so I can highlight the current link?

被刻印的时光 ゝ 提交于 2019-11-30 23:54:38
I'm trying to get the current Route into my navigation controller so I can run comparisons as the navigation menu data is populated. My Links object is like this: public class StreamNavLinks { public string Text { get; set; } public RouteValueDictionary RouteValues { get; set; } public bool IsSelected { get; set; } } In the master page, I'm trying to pass the current route to the nav controller like this: <% Html.RenderAction( "MenuOfStreamEntries", // action "Nav", // controller new { // parameters for action currentStreamUrl = "Blog", currentRoute = ViewContext.RouteData } // get route data

ASP.NET MVC 2.0 - Difference between RenderPartial and RenderAction

给你一囗甜甜゛ 提交于 2019-11-30 23:13:19
问题 I am trying to understand the difference between a RenderPartial and RenderAction. I guess that RenderPartial is like a UserControl and RenderAction is like a server-side include. Can someone put this in perspective please and if possible give me a couple scenarios of where each would be used? 回答1: Have you seen this blog post? Summary: RenderPartial: You are responsible for providing a model, performing logic etc. RenderAction: You are responsible for invoking an action, that controller is

Multiple Controllers with one Name in ASP.NET MVC 2

放肆的年华 提交于 2019-11-30 22:59:08
问题 I receive the following error when trying to run my ASP.NET MVC application: The request for 'Account' has found the following matching controllers: uqs.Controllers.Admin.AccountController MvcApplication1.Controllers.AccountController I searched the project for MvcApplication1.Controllers.AccountController to remove it, but I can't find a match. I try to registered a route to fix it: routes.MapRoute( "LogAccount", // Route name "{controller}/{action}/{id}", // URL with parameters new {

format int to phone number

北战南征 提交于 2019-11-30 22:50:20
Is there a way I can format for example: 0000000000 into (000)000-0000? I'm returning a listbox which holds a collection of phone number which arent formated yet. What I would like is format it. This is what I have in the View: <%= Html.ListBox("phoneList")%> and from the controller: ViewData["phoneList"] = new SelectList(phoneList); Edit $('#phoneList').each(function() { var phoneNumber = $(this).text(); var formatPhoneNumber = phoneNumber.replace(/(\d{3})(\d{3})(\d{4})/, '($1)$2-$3'); alert(formatPhoneNumber); }); how would I assign this back to show in the ListBox? If you're saying that you

Custom ViewModel with MVC 2 Strongly Typed HTML Helpers return null object on Create?

≡放荡痞女 提交于 2019-11-30 21:52:05
I am having a trouble while trying to create an entity with a custom view modeled create form. Below is my custom view model for Category Creation form. public class CategoryFormViewModel { public CategoryFormViewModel(Category category, string actionTitle) { Category = category; ActionTitle = actionTitle; } public Category Category { get; private set; } public string ActionTitle { get; private set; } } and this is my user control where the UI is <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CategoryFormViewModel>" %> <h2> <span><%= Html.Encode(Model.ActionTitle) %></span>

Wondering why DisplayName attribute is ignored in LabelFor on an overridden property

假如想象 提交于 2019-11-30 21:46:11
问题 today I got confused when doing a couple of <%=Html.LabelFor(m=>m.MyProperty)%> in ASP.NET MVC 2 and using the [DisplayName("Show this instead of MyProperty")] attribute from System.ComponentModel . As it turned out, when I put the attribute on an overridden property, LabelFor didn't seem to notice it. However, the [Required] attribute works fine on the overridden property, and the generated errormessage actually uses the DisplayNameAttribute. This is some trivial examplecode, the more