asp.net-mvc-2

ControllerFactory for specific portable area

≡放荡痞女 提交于 2019-12-03 15:26:14
My main ASP.NET MVC composite application uses a global Unity container to register types. The app sets the controller factory up to use this global container. I would like to refactor this such that each one of my portable areas leverages it's own child Unity container, so that different areas can implement interfaces in varying ways. It seems like I would need to have a different ControllerFactory per area. How would I accomplish that, given that the following sets the factory for all? ControllerBuilder.Current .SetControllerFactory(/* controller factory with global unity container */); You

MVC and EditorFor width

荒凉一梦 提交于 2019-12-03 14:46:57
问题 Can I set the width of an EditorFor control on my View? I have set a few parameters: [Required, DisplayName("Payee Name"), StringLength(50)] public string Name { get; set; } However, I can't seem to set the width of the textbox that gets rendered. <table width="300" border="0" cellpadding="3" cellspacing="0"> <tr> <td> <%=Html.LabelFor(m => m.Name)%> </td> <td> <%=Html.EditorFor(m => m.Name)%> </td> </tr> Can this be done somehow? I tried: <%=Html.EditorFor(m => m.Name, new {width=50)%> But

Entity Framework CTP4: where to put SetInitializer?

倖福魔咒の 提交于 2019-12-03 14:46:25
I am attempting to add Entity Framework, code first, to an MVC application that's been running with test data, using the CTP4 preview. I am currently getting this error: The model backing the 'SchedulerContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the RecreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data. I do not want to generate a database at all, as I already have a database.

Where should ASP.NET MVC 2 validation go: in the model or viewmodel classes?

有些话、适合烂在心里 提交于 2019-12-03 14:40:44
I am using automapper to map my models to viewmodel classes to pass to my view. My question really is where should the validation go? I was planning on using the MetaData decorations - a feature of mvc 2. But either in the model or viewmodel? Or in both places? Validation should be done minimum at the View Model because this is what you receive as action argument and contains the user input. You could also have validation at the model. My answer would be ViewModel because Model can change (for example from using Linq2SQL to EF). This way when you plug another Model you still have your

Update A Partial View From Another Partial View - ASP.NET MVC2

拈花ヽ惹草 提交于 2019-12-03 14:28:29
I want to have two partial views , one for SEARCH and one for SEARCHRESULTS . I want to update SEARCHRESULTS when the "Search" Button is clicked on the SEARCH partial view form. SEARCHRESULTS needs to have the form data fed to it from the SEARCH partial view. I'm not totally sure how to go about this. Can I update the SEARCHRESULTS partial view from my SEARCH partial view's Controller action? General Discussion In the MVC design pattern views are unaware of each other. They may be bound together by the concept of a view assembling multiple partial views but even then the partials are ignorant

ASP.NET MVC Redirect with model

扶醉桌前 提交于 2019-12-03 14:26:00
问题 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

Can I have an ActionResult called “View”

ε祈祈猫儿з 提交于 2019-12-03 14:25:39
Code: public ActionResult View(string id) { return View(); } I currently get stackoverflow exceptions when I do this. You should be getting a compiler warning that your definition of View masks that of the base controller class and that you should explicitly use the new keyword. If you change your code to do this instead, it should work as you'd like: return base.View(); Of course, just don't call yourself recursively: public new ActionResult View() { return base.View(); } It's generally a good idea to name your views descriptively. A view named View doesn't say what the view does or the data

Are there any non-obvious dangers in using threads in ASP.NET?

旧街凉风 提交于 2019-12-03 14:16:03
问题 This is something of a sibling question to this programmers question. Briefly, we're looking at pushing some work that's been piggy-backing on user requests into the background "properly." The linked question has given me plenty of ideas should we go the service route, but hasn't really provided any convincing arguments as to why, exactly, we should. I will admit that, to me, the ability to do the moral equivalent of WorkQueue.Push(delegate(object context) { ... }); is really compelling, so

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

孤人 提交于 2019-12-03 14:15:06
问题 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;

MVC 2.0 dynamic routing for category names in an e-store

北城以北 提交于 2019-12-03 14:13:37
I'm currently working on an e-store using ASP.NET MVC 2.0. I already got most of it up and running, but the part that's been bothering me is routing. I want this: http://mystore.somewhere/my-category-1/ So far I've been able to solve it by using: routes.MapRoute( "Category", "{alias}/{pageNumber}", new { controller = "Categories", action = "Browse", pageNumber = 1 }); But this catches way too much than just what I'd like. After reading through some questions and answers around this site, I found a particulary interesting solution that would require me to programatically register a route for