asp.net-mvc-2

Problem performing Ajax call from ASP.NET MVC2 app

好久不见. 提交于 2019-12-01 19:27:20
问题 I'm converting an existing ASP.NET app to MVC2, and I have an existing method that is called through jQuery using Ajax, that worked before, but does not work now. So it seems there are some change I need to do due to using MVC2 that I can't figure out. I have reduced the complexity of the code, but it still do not work. This is my current code: jQuery script that trigger on button click function leaveComment() { if (validate()) { $.ajax({ type: "POST", url: "/Pages/PostBlogComment", data: "{

Why can't I set a breakpoint in a ASP.NET view?

有些话、适合烂在心里 提交于 2019-12-01 18:53:50
If I set a breakpoint in the compiled code (for instance in an action), I can then step through, and eventually am stepping through the generation of the View. I've found this useful a couple of times, but it's tedious as you have to step through a lot of code to get there. However, I can't set a breakpoint in view. I just receive the message 'This is not a valid location for a breakpoint' from VS2008. Why is this? Right click on the code you want to break on and go to "Breakpoint -> Insert Breakpoint". Why? Must have something to do with the face your not working with a pure code file and

Back button not requesting asp.net mvc get method

若如初见. 提交于 2019-12-01 18:36:46
We are facing a specific problem where in on click of backbutton, the default get method is not getting triggered in asp.net mvc any specific solutions ? John Smith If the browser has the page cached, it'll use the one from cache. Try telling the response not to cache. You can do it with an ActionFilter or globally in Global.asax. httpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1)); httpContext.Response.Cache.SetValidUntilExpires(false); httpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches); httpContext.Response.Cache.SetCacheability(HttpCacheability

How can I make HandleErrorAttribute work with Ajax?

别来无恙 提交于 2019-12-01 18:22:00
In my ASP.NET MVC 2 application I use HandleErrorAttribute to display a custom error page in case of unhandled exceptions, and it works perfectly unless the exception happens in an action called by Ajax.ActionLink. In this case nothing happens. Is it possible to use HandleErrorAttribute to update the target element with the contents of an "Error.ascx" partial view? To achieve this you could write a custom action filter: public class AjaxAwareHandleErrorAttribute : HandleErrorAttribute { public string PartialViewName { get; set; } public override void OnException(ExceptionContext filterContext)

Child actions are not allowed to perform redirect actions - error while working with ASP.NET MVC 2 and Razor

末鹿安然 提交于 2019-12-01 18:19:22
In _Layout.cshtml file I have following entry: @Html.Action("LoadPagesStructure", "Page") Inside PageController class, LoadPagesStructure methos looks following: [ChildActionOnly] /* this attribute indicates that an action should not be invoked as a result of a user request (by url) */ public ActionResult LoadPagesStructure() { ViewModel.Pages = new List<string>() {"page1", "page2", "page3"}; return View(); } Finally, my LoadPagesStructure.cshtml view looks like below: @inherits System.Web.Mvc.WebViewPage<dynamic> <ul> @foreach (var page in View.Pages) { <li> @Html.ActionLink(page, "Index",

error running asp.net mvc 2 project out of the box in vs 2010

那年仲夏 提交于 2019-12-01 18:08:39
问题 i created a new solution and it builds fine targeting framework 4.0 but when i run it, my browser comes up saying: The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: / any ideas on how to debug this? 回答1: Try adding the default.aspx page that comes with the asp

ASP.NET MVC 2 RC client side validation not working

為{幸葍}努か 提交于 2019-12-01 18:08:01
I can't seem to get any client side validation working on a MVC 2 RC app. My model has the following: public class ExampleModel { [Required(ErrorMessage="Test1 is required")] [DisplayName("Test1")] public string Test1 { get; set; } [Required(ErrorMessage="Test2 is required")] [DisplayName("Test2")] public string Test2 { get; set; } } My view has the following code: <% Html.EnableClientValidation(); %> <%= Html.ValidationSummary(true, "Test was unsuccessful.") %> <% using (Html.BeginForm()) { %> <div> <div class="editor-label">Test1:</div> <div class="editor-field"> <%= Html.TextBoxFor(m => m

error running asp.net mvc 2 project out of the box in vs 2010

六眼飞鱼酱① 提交于 2019-12-01 17:49:51
i created a new solution and it builds fine targeting framework 4.0 but when i run it, my browser comes up saying: The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: / any ideas on how to debug this? Try adding the default.aspx page that comes with the asp.net mvc 1.0 project template. I had a similar issue running mvc 2 out of the box on a computer with IIS 5 (XP)

Only allow access to action if redirected from specific action

旧时模样 提交于 2019-12-01 17:40:45
Is there a good way to restrict the access to an action, so you can only access it, if you were redirected from another action. For example: [HttpPost] public virtual ActionResult Create(MyViewModel vm) { if (ModelState.IsValid) { // do some work return RedirectToAction("CreateSuccess"); } else { return View(vm); } } public virtual ActionResult CreateSuccess() { // only allow execution if you were redirected from Action "Create" } An easy way would be to store a flag in TempData in the first method and check that the flag exists in the method that is redirected to. TempData is there to pass

Custom validation attribute with multiple instances problem

元气小坏坏 提交于 2019-12-01 17:31:23
问题 I'm using tha namespace System.ComponentModel.DataAnnotations in C# 4 to implement my own validation attribute and it looks like this [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public sealed class MyCustomValidator : ValidationAttribute { private String Property1 { get; set; } private String Property2 { get; set; } public ValeTaxiSituacaoRequired(String property1, String property2) { Property1 = property1; Property2 = property2; } public override bool IsValid(object value)