asp.net-mvc-2

Undoing “Set as Start Page”

丶灬走出姿态 提交于 2019-12-10 01:23:59
问题 I set one of my ASP.net pages to the default start page in Visual Studio. This results in a 404 error when I try to debug my project. How do I clear this? Thanks, Barry 回答1: Right click the MVC project and select properties. Go to the Web tab. Under Start Action, select either Current Page or Don't open a page. 来源: https://stackoverflow.com/questions/8464070/undoing-set-as-start-page

How do build a composite or template control in ASP.Net MVC, or the equivelant?

你说的曾经没有我的故事 提交于 2019-12-09 20:24:50
问题 In our current ASP.Net Webforms application we have several composite/template server controls that only exist for a common look and feel. For example, we have a panel control that has a title, a place for buttons related to the contents of the panel, and of course the contents. How is this best accomplished in MVC? RenderPartial doesn't get done what I need here. Should I still be using the same controls, but just on a view page? These controls don't really do anything on postback, they are

keeping asp.net mvc controller size down

廉价感情. 提交于 2019-12-09 18:22:25
问题 I have a Controller. "OrderController". Currently it's 1800 lines. I like to reduce the size. I'm using static helper methods which is fine but i'm using ninject to call my repositories so don't have access to the repositories in the static methods without passing the properties in. What are some good approaches for reducing controller noise? 回答1: How to get a Thin Controller Refactor reusable functionalities that can apply to multiple types of output to ActionFilters . Consequence: Less

How to use ASP.Net MVC View inside WebForms .aspx page?

谁说我不能喝 提交于 2019-12-09 17:41:10
问题 I have a large web application that I have set up as both ASP.Net Web Forms and MVC. Some of the newer pages are MVC (.mvc) and some are Web Forms (.aspx). Since this is a business app and functions are being constantly added, it's hard for me to have the time to stop and replace existing functionality to convert it over. So I would like to do it piece by piece, control by control. To do this, all I would need to be able to do is to replace certain controls with <% Html.RenderPartial() %> or

Editing an object in entity framework and saving it to the database in ASP.NET MVC 2.0

微笑、不失礼 提交于 2019-12-09 16:08:11
问题 So I know that EF entities track their own changes and persist them to the database when savechanges is called, but what about this scenario... I have a page that is designed to edit a blog post. It has two action methods. [HttpGet] public ViewResult EditBlogPost(int Id) { //This action method gets the blog post by the id and returns the edit blog post page. BlogPost blogPost = db.BlogPosts.Where(x => x.Id == Id).FirstOrDefault(); if (blogPost == null) { ViewData["message"] = "Blog post not

Building unit tests for MVC2 AsyncControllers

安稳与你 提交于 2019-12-09 15:14:31
问题 I'm considering re-rewriting some of my MVC controllers to be async controllers. I have working unit tests for these controllers, but I'm trying to understand how to maintain them in an async controller environment. For example, currently I have an action like this: public ContentResult Transaction() { do stuff... return Content("result"); } and my unit test basically looks like: var result = controller.Transaction(); Assert.AreEqual("result", result.Content); Ok, that's easy enough. But when

Access “Application” object in ASP.Net MVC to store application wide variables

廉价感情. 提交于 2019-12-09 14:34:57
问题 How do I store a variable or object application wide in ASP.net MVC? In regular ASP, you had the Application object and in ASP.net too apparently. I'm using ASP.net MVC 2. 回答1: In a controller you should be able to do this: this.HttpContext.Application["foo"] = "bar"; 来源: https://stackoverflow.com/questions/3430839/access-application-object-in-asp-net-mvc-to-store-application-wide-variables

Custom errors override in ASP.NET MVC area

旧巷老猫 提交于 2019-12-09 13:07:17
问题 I would like to have custom error pages unique to an MVC area. Unfortunately, it appears that the Web.config override system doesn't take the MVC folder structure into account. If I want to override an area called "mobile", I have to create a root project folder (in with Views and Controllers) named "mobile" and put the Web.config in there with the new customErrors element. Is there some better way to do this so that I don't have to create a root folder for any overrides? 回答1: I've been

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

不问归期 提交于 2019-12-09 12:46:24
问题 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? 回答1: 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. 回答2: My answer would be ViewModel because Model can

Setting visibility of a textbox in MVC3 Razor view engine

守給你的承諾、 提交于 2019-12-09 12:19:11
问题 I am new to MVC 3, razor view engine. I want to set the visibility of a textbox at runtime as per the value in my viewmodel. But the below code is not working. <td> @Html.TextBox("CompanyName", "", new { visible = "false" }) </td> Once above code starts working, I could place @Model.EnableCompanyName in place of hardcoded "false". So please help me in rectifying the above code. 回答1: This will change the display type based on your bool Model.EnableCompanyName :) Hope it helps! @{ String