Error Message In Asp.net Mvc
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn
Aspnet Mvc Nuget
more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users aspnet mvc source Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping
Aspnet Mvc Tutorial
each other. Join them; it only takes a minute: Sign up return error message with actionResult up vote 10 down vote favorite 2 MVC App, client makes request to server, error happens, want to send the msg back aspnet mvc 5 to the client. Tried HttpStatusCodeResult but just returns a 404 with no message, I need the details of the error sent back to the client. public ActionResult GetPLUAndDeptInfo(string authCode) { try { //code everything works fine } catch (Exception ex) { Console.WriteLine(ex.Message); return new HttpStatusCodeResult(404, "Error in cloud - GetPLUInfo" + ex.Message); } } c# asp.net-mvc asp.net-mvc-3 actionresult share|improve this question edited Feb 10 '14 at 17:27 MikeSmithDev 11.6k43059 asked Feb 10 '14 at 16:26 John aspnet mvc 4 1,26342663 add a comment| 4 Answers 4 active oldest votes up vote 7 down vote You need to return a view which has a friendly error message to the user catch (Exception ex) { // to do :log error return View("Error"); } You should not be showing the internal details of your exception(like exception stacktrace etc) to the user. You should be logging the relevant information to your error log so that you can go through it and fix the issue. If your request is an ajax request, You may return a JSON request with a proper status flag which client can evaluate and do further actions [HttpPost] public ActionResult Create(CustomerVM model) { try { //save customer return Json(new { status="success",message="customer created"}); } catch(Exception ex) { //to do: log error return Json(new { status="error",message="error creating customer"}); } } If you want to show the error in the form user submitted, You may use ModelState.AddModelError method along with the Html helper methods like Html.ValidationSummary etc to show the error to the user in the form he submitted. share|improve this answer edited Feb 10 '14 at 16:34 answered Feb 10 '14 at 16:28 Shyju 94.9k71250373 add a comment| up vote 5 down vote One approach would be to just use the ModelState: ModelState.AddModelError("", "Error in cloud - GetPLUInfo" + ex.Message); and then on the view do something like this: @Html
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question View Unanswered Questions View All Questions...
Aspnet Mvc Cms
C# questions Linux questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message aspnet mvc 6 Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript
Aspnet Mvc 3
C / C++ / MFC> ATL / WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile http://stackoverflow.com/questions/21682581/return-error-message-with-actionresult SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What http://www.codeproject.com/Questions/679815/How-to-Display-a-error-message-in-view-from-contro is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ How to Display a error message in view from controller,MVC 4? Rate this: Please Sign up or sign in to vote. See more: MVC Hi.. I am new to MVC 4. I am developing a simple application in MVC 4 using Razor in c#. Now i need to Display a error in view which is pass from controller? How can i achieve it? MY CODES: MY VIEW CODE: ------------- @model mvc_cs.Models.FormModels @using ctrlr = mvc_cs.Controllers.FormController @{ ViewBag.Title = "form_edit"; Layout = "~/Views/Shared/_Layout.cshtml"; }
form_edit
MY CONTROLLER: -------------- [HttpPost] public ActionResult form_edit(FormModels model) { model.error_msg = model.update_content(model); TempData["error"] = "fjghsfhgflsh"; ModelState.AddModelError("error.error", "adfdghdghgdhgdhdgda"); return RedirectToAction("Form_edit", "Form",model.error_msg); } Posted 7-Nov-13 20:35pm srameshsathy277 Updated 8-Nov-13 1:32am Pratik Bhuva5.2K v2 Add a Solution 2 solutions Top Rated Most Recent Rate this: Please Sign up or sign in to vote. Solution 1 Accept Solution Reject Solution You can send your error as above using TemData for the next action method.Inside the redirected action method use ViewBag for put aPortability Issues C++ & MFC » General Array Handling Binary Trees Bits and Bytes Buffer & Memory Manipulation Callbacks Classes and Class Use Collections Compression Drag and Drop Events Exceptions http://www.codeguru.com/csharp/.net/net_asp/mvc/handling-errors-in-asp.net-mvc-applications.htm External Links File I/O Function Calling Linked Lists Memory Tracking Object Oriented Programming https://documentation.devexpress.com/AspNet/CustomDocument12311.aspx (OOP) Open FAQ Parsing Patterns Pointers Portability RTTI Serialization Singletons Standard Template Library (STL) Templates Tutorials Date & Time » General Date Controls Time Routines C++/CLI » .NET Framework Classes General ASP/ASP.NET Boxing and UnBoxing Components Garbage Collection and Finalizers Interop Moving from Unmanaged Processes & Threads Templates Visual aspnet mvc Studio .NET 2003 String Programming » General CString Alternatives CString Extensions CString Manipulation Open FAQ Regular Expressions String Arrays String Conversions .NET COM-based Technologies » ATL & WTL Programming » General ATL Active Scripting ActiveX Controls Database Debugging External links Graphics Support Misc. Performance Printing Tutorials Utilities Windows Template Library (WTL) ActiveX Programming » General Active Scripting ActiveX Controls ActiveX Documents error message in Apartments & Threading Error Handling External links General COM/DCOM Misc. Registry Security Structured Storage Tutorials Wrappers COM+ » General COM Interop Managed Code / .NET SOAP and Web Services Shell Programming » General Open FAQ Shortcuts Tray Icons Previous Section Manager Controls » Property Sheet » Open FAQ Property Sheet Buttons Sizing Wizards Button Control » Advanced Buttons Bitmap Buttons Flat Buttons Menus Non-Rectangular buttons Windows XP ComboBox » Colour Pickers DropDown Font selection combos Multicolumn combos Special Effects Tooltips Edit Control » Background & Color Editors Keyboard Masked Edit Controls Passwords and Security Spin Controls Transparent ImageList Control » Open FAQ ListBox Control » Checkboxes Color Listboxes Drag & Drop LEDs ListView Control » Advanced Background color and image Checkboxes Columns Custom Drawing Data Deleting Drag & Drop Editing items and subitem FilterBar Grid lines Header Control Introduction Miscellaneous Navigation New ListView control (IE 4.0) Printing Property Lists Reports Scrollbars Selection Sorting Tooltip & Titletip Using images Views Menu » Alternative menu Bitmapped menus Dockable menus Message and Command Routing Miscellaneous XML XP-Style Menus Other Controls » Bitmap Buttons Charting and ana
Server Dashboard eXpressApp Framework CodeRush Cross-Platform Core Libraries Tools and Utilities End-User Documentation Loading…