actionresult

Actionlink with no routeValues being loaded with routeValue breaking dynamic pages

南笙酒味 提交于 2019-12-24 08:34:50
问题 When you have an actionlink that is written with no routeValues and you load that page with a routeValue specified MVC writes out the actionlink incorrectly. I have had exactly the same bug with MVC attribute routing as well where you specify a url something like this: [Route("reviews/{reviewId}")] I have escpecially had problems with this where it breaks dynamic content pages that are loaded by a routeValue and when you have multiple actionlinks that point to the dynamic action result on the

ASP.NET MVC ActionResult View() not changing url

大城市里の小女人 提交于 2019-12-24 02:44:16
问题 I have a method... [HttpPost] public ActionResult Start(SomeViewModel someViewModel) { ... } that based on some conditions returns things like return View("Invalid") , View("NotFound") , View("Run", anotherViewModel) , etc. The problem is that no matter what view I present, the URL does not change to reflect the new controller/action. This poses a problem when my View wants to post to a different action. How can I fix this? 回答1: The View(...) methods don't redirect, they simply render out the

MVC Equivalent of Page_Load

回眸只為那壹抹淺笑 提交于 2019-12-23 09:34:23
问题 I have a session variable that is set in my MVC application. Whenever that session expires and the user tries to refresh the page that they're on, the page will throw an error because the session is not set anymore. Is there anywhere I can check to see if the session is set before loading a view? Perhaps putting something inside the Global.asax file? I could do something like this at the beginning of EVERY ActionResult . public ActionResult ViewRecord() { if (MyClass.SessionName == null) {

ActionRedirect migration to Struts 2

冷暖自知 提交于 2019-12-23 03:07:31
问题 I'm currently migrating a wepapp from Struts to Struts 2 and I'm experiencing some difficulties. I have some ActionRedirect with no extra parameters given to it and I don't know how to migrate it, maybe just return a string is efficient? For example I have this : return new ActionRedirect(mapping.getFindforward("failed"); Is it efficient to do that instead ? return "failed"; And when I have parameters how can i migrate it ? I'm working on that part since 2 days. 回答1: In Struts2 redirects are

MVC Handler for an unknown number of optional parameters

风格不统一 提交于 2019-12-22 10:27:58
问题 I am workingon an MVC route that will take an unknown number of parameters on the end of the URL. Something like this: domain.com/category/keyword1/keyword2/.../keywordN Those keywords are values for filters we have to match. The only approach I can think of so far is UGLY... just make an ActionResult that has more parameters than I am ever likely to need: ActionResult CategoryPage(string urlValue1, string urlValue2, string urlValue3, etc...) { } This just doesn't feel right. I suppose I

Difference between FileStreamResult and FilePathResult?

走远了吗. 提交于 2019-12-21 07:10:22
问题 I have a simple controller which returns images: public class ImageController : Controller { [AcceptVerbs(HttpVerbs.Get)] [OutputCache(CacheProfile = "StationeryImageCache")] public FileResult Show(int customerId, string imageName) { try { var path = string.Concat(Config.ImageDir, customerId, @"\", imageName); return new FileStreamResult(new FileStream(path, FileMode.Open), "image/jpeg"); } catch(System.IO.FileNotFoundException ex) { throw new MissingImageException(imageName); } } } My

MVC3 - Ajax loading icon

≡放荡痞女 提交于 2019-12-20 09:45:40
问题 I would like to show an AJAX loading icon during an ActionResult request that can take a few seconds to process. What is the best approach to accomplished this? I only want to display the icon after the built it validation passes (I am using MVC3, EF Code First, so the validation is automatically put on the page). There may be further validation/exceptions during the ActionResult, in which case a message is displayed to the user, and I'd then want the loading icon to disappear again. 回答1:

Calling httppost actionresult from inside a view using a button

你说的曾经没有我的故事 提交于 2019-12-20 04:50:22
问题 I have a project to make an online shop between users (post a product, buy, etc.) using a database. In this project I have a view called "ShoppingCart": @model IEnumerable<MyFirstProject.Models.Product> @{ ViewBag.Title = "ShoppingCart"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2>Your Shopping Cart</h2> @if (Model == null) { <div style="float:left">Your cart is empty.</div> <div> Total payment: 0 </div> } else { decimal tPrice = 0; <div> <table style="float:left"> @foreach (var product

Download file from ajax and ActionResult

时光怂恿深爱的人放手 提交于 2019-12-20 03:23:53
问题 I want to download files on browser with ajax and ActionResult. The file is downloaded and returned from my ActionResult. I see the Http query is ok and see the data in the response body. The problem is that the file is not proposed to save in the browser. All seems good. All that I seen in tutorial and forum were like I done but mine don't word XD. I don't understand what is the difference between mine and the others. Here is my ActionResult : public ActionResult ShippingDownloadDNPriority

All inbuilt ActionResults in ASP.NET MVC

99封情书 提交于 2019-12-19 10:03:16
问题 I'm looking for a list of the inbuilt (and 3rd party would be a bonus) ActionResults you have available to you in a controller in ASP.NET MVC. So far I've discovered the following: ContentResult - this.Content() ActionResult - this.View() JsonResult - this.Json() JavascriptResult - this.Javascript() PartialViewResult - this.PartialView() Have I missed any useful ones that are out there? 回答1: From this source: ContentResult Writes a string value directly into the HTTP response. EmptyResult