asp.net-mvc-2

“Run Custom Tool” for resx files in MVC2 project (from an external application/script)

ぐ巨炮叔叔 提交于 2019-11-27 07:10:50
问题 I am trying to get the localization for my MVC project working with our existing infrastructure for editing string resources. We store all our resource string in database tables and have a front end web UI to edit them with, and an export application which generated the .resx files. This all works great, but I am having a little difficulty with a new project using MVC2 and VS2010. I have asked another question on this, the answer to which almost got me there, but not quite. I have now changed

How to achieve a dynamic controller and action method in ASP.NET MVC?

血红的双手。 提交于 2019-11-27 06:59:29
In Asp.net MVC the url structure goes like http://example.com/ {controller}/{action}/{id} For each "controller", say http://example.com/blog , there is a BlogController. But my {controller} portion of the url is not decided pre-hand, but it is dynamically determined at run time, how do I create a "dynamic controller" that maps anything to the same controller which then based on the value and determines what to do? Same thing with {action}, if the {action} portion of my url is also dynamic, is there a way to program this scenario? Ryan Absolutely! You'll need to override the

Asynchronous Controller is blocking requests in ASP.NET MVC through jQuery

别来无恙 提交于 2019-11-27 06:54:55
I have just started using the AsyncController in my project to take care of some long-running reports. Seemed ideal at the time since I could kick off the report and then perform a few other actions while waiting for it to come back and populate elements on the screen. My controller looks a bit like this. I tried to use a thread to perform the long task which I'd hoped would free up the controller to take more requests: public class ReportsController : AsyncController { public void LongRunningActionAsync() { AsyncManager.OutstandingOperations.Increment(); var newThread = new Thread(LongTask);

What is the default behaviour of a controller action not marked with AcceptVerbs, HttpGet or HttpPost?

人盡茶涼 提交于 2019-11-27 06:51:35
问题 If I create a controller action and do not decorate it with AcceptVerbs , HttpPost or HttpGet . What is the default behaviour? Does the action allow any access method or does it default to GET ? 回答1: It's accessible via any verb. 回答2: In Web API 2.1: it depends on the name of the action. If the action starts with "Get*" then it will default to only accept GET requests. If it starts with "Put*" then it will default to only accept PUT requests. Same with POST. If it doesn't start with any known

ActionLink htmlAttributes

两盒软妹~` 提交于 2019-11-27 06:46:51
WORKS <a href="@Url.Action("edit", "markets", new { id = 1 })" data-rel="dialog" data-transition="pop" data-icon="gear" class="ui-btn-right">Edit</a> DOES NOT WORK - WHY? @Html.ActionLink("Edit", "edit", "markets", new { id = 1 }, new {@class="ui-btn-right", data-icon="gear"}) It seems you can't pass something like data-icon="gear" into htmlAttributes? Suggestions? The problem is that your anonymous object property data-icon has an invalid name. C# properties cannot have dashes in their names. There are two ways you can get around that: Use an underscore instead of dash (MVC will automatically

Adding sub-directory to “View/Shared” folder in ASP.Net MVC and calling the view

大兔子大兔子 提交于 2019-11-27 06:43:53
I'm currently developing a site using ASP.Net MVC3 with Razor. Inside the "View/Shared" folder, I want to add a subfolder called "Partials" where I can place all of my partial views (for the sake of organizing the site better. I can do this without a problem as long as I always reference the "Partials" folder when calling the views (using Razor): @Html.Partial("Partials/{ViewName}") My question is if there is a way to add the "Partials" folder to the list that .Net goes through when searching for a view, this way I can call my view without having to reference the "Partials" folder, like so:

using Html.EditorFor with an IEnumerable<T>

半腔热情 提交于 2019-11-27 06:21:44
问题 I have a custom class: public class Person { public String Name { get; set; } public Int32 Age { get; set; } public List<String> FavoriteFoods { get; set; } public Person() { this.FavoriteFoods = new List<String>(); this.FavoriteFoods.Add("Jambalya"); } } I pass this class to my strongly typed view: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcLearner.Models.Person>" %> <asp:Content ID="Content1" ContentPlaceHolderID=

File download in Asp.Net MVC 2

≡放荡痞女 提交于 2019-11-27 06:20:59
问题 I want to enable file download in my MVC application, without simply using a hyperlink. I plan to use an image or the like and make it clickable by using jQuery. At the moment I have a simple just for testing. I found an explanation of doing the download through an action method, but unfortunately the example still had actionlinks. Now, I can call the download action method just fine, but nothing happens. I guess I have to do something with the return value, but I don't know what or how. Here

How to implement proper HTTP error handling in .NET MVC 2?

流过昼夜 提交于 2019-11-27 06:19:24
I've been struggling all day to implement error handling in my ASP.NET MVC 2 app. I've looked at a variety of techniques, but none work properly. I'm using MVC2 and .NET 4.0 (started the project before MVC3 was released; we'll upgrade after we deliver our initial release). At this point, I'll be happy to properly handle 404 and 500 errors -- 403 (authorization required) would be great, too, followed by various other specific responses. Right now, I either get all 404s, all 500s, all 302s before the 404, or all 302s before the 500. Here are my requirements (which should be pretty close to the

How to specify an area name in an action link?

一个人想着一个人 提交于 2019-11-27 06:14:42
I have a shared master page which I am using from 2 different areas in my mvc 2 app. The master page has an action link which currently specifies the controller and action, but of course the link doesn't work if I'm in the wrong area. I see no overload for actionlink that takes an area parameter, is it possible to do? Figured it out.. Html.ActionLink("Link Text", "ActionName", "ControllerName", new { Area = "AreaName" }, new{}) Something I ran into right after this, that I imagine others might run into: If you need to link from within an area to an action not in an area, you still need to