asp.net-mvc-2

ASP.NET MVC and IE caching - manipulating response headers ineffective

♀尐吖头ヾ 提交于 2019-11-26 13:22:08
Background I'm attempting to help a colleague debug an issue that hasn't been an issue for the past 6 months. After the most recent deployment of an ASP.NET MVC 2 application, FileResult responses that force a PDF file at the user for opening or saving are having trouble existing long enough on the client machine for the PDF reader to open them. Earlier versions of IE (expecially 6) are the only browsers affected. Firefox and Chrome and newer versions of IE (>8) all behave as expected. With that in mind, the next section defines the actions necessary to recreate the issue. Behavior User clicks

ActionLink htmlAttributes

≡放荡痞女 提交于 2019-11-26 12:56:08
问题 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? 回答1: The problem is that your anonymous object property data-icon has an invalid name. C# properties

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

亡梦爱人 提交于 2019-11-26 12:14:07
问题 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

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

删除回忆录丶 提交于 2019-11-26 12:08:35
问题 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

Showing Difference between two datetime values in hours

空扰寡人 提交于 2019-11-26 12:08:21
I am retrieving two date time values from the database. Once the value is retrieved, I need the difference between the two values. For that, I create a timespan variable to store the difference of the 2 date values. TimeSpan? variable = datevalue1 - datevalue2; Now i need to show the difference which is stored in the Timespan variable in terms of number of hours. I referred to TimeSpan.TotalHours but couldn't apply the same for some reason. How do I do that? I am using C# on a MVC project. I simple need to show the difference value in hours? EDIT: Since timespan was nullable, i couldn't use

How to specify an area name in an action link?

十年热恋 提交于 2019-11-26 11:56:18
问题 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? 回答1: Figured it out.. Html.ActionLink("Link Text", "ActionName", "ControllerName", new { Area = "AreaName" }, new{}) 回答2: Something I ran into right after this, that I imagine

ModelState.AddModelError - How can I add an error that isn&#39;t for a property?

白昼怎懂夜的黑 提交于 2019-11-26 11:53:39
问题 I am checking my database in Create(FooViewModel fvm){...} to see if the fvm.prop1 and fvm.prop2 already exist in that combination; if so, I want to add an error to the modelstate, then return the whole view. I tried: public ActionResult Create(FooViewModel fvm){ if (ThatComboAlreadyExists(fvm)) { ModelState.AddModelError(\"Model\", \"There is already one like that\"); return View(fvm); } } ...but I get no display of errors in the Html.ValidationSummary , which is where I assume they would

Are <%: and <%= the same thing as embbed code (expression) blocks

 ̄綄美尐妖づ 提交于 2019-11-26 11:19:50
问题 Having just started with MVC 2 I notice that in their starter template they use <%: Html.ActionLink(\"Home\", \"Index\", \"Home\")%> and I was sure that in MVC 1 it was <%= Html.ActionLink(\"Home\", \"Index\", \"Home\")%> Are they the same thing? If so, why the change from equal sign to colon. 回答1: the colon syntax means you'll be html encoded automatically: http://haacked.com/archive/2009/09/25/html-encoding-code-nuggets.aspx They couldn't just html encode all the existing <%= blocks,

Asp.Net MVC 2 - Bind a model&#39;s property to a different named value

馋奶兔 提交于 2019-11-26 11:12:28
Update (21st Sept 2016) - Thanks to Digbyswift for commenting that this solution still works in MVC5 also. Update (30th April 2012) - Note to people stumbling across this question from searches etc - the accepted answer is not how I ended up doing this - but I left it accepted because it might have worked in some cases. My own answer contains the final solution I used , which is reusable and will apply to any project. It's also confirmed to work in v3 and v4 of the MVC framework. I have the following model type (the names of the class and its properties have been changed to protect their

When `PostAuthenticateRequest` gets execute?

こ雲淡風輕ζ 提交于 2019-11-26 11:12:03
问题 This is my Global.asax.cs file: public class MvcApplication : System.Web.HttpApplication { public static void RegisterRoutes(RouteCollection routes) { ... } protected void Application_Start() { this.PostAuthenticateRequest += new EventHandler(MvcApplication_PostAuthenticateRequest); } // This method never called by requests... protected void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e) { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; if