actionmethod

Error during serialization using the JSON JavaScriptSerializer. Should be using the JSON.NET JsonSerializer

早过忘川 提交于 2020-01-05 08:41:56
问题 I've added Newton Soft to the mix and am using this blog as a template: http://wingkaiwan.com/2012/12/28/replacing-mvc-javascriptserializer-with-json-net-jsonserializer/ I now have: public class BaseJsonController : BaseController { protected override JsonResult Json(object data, string contentType, Encoding contentEncoding, JsonRequestBehavior behavior) { return new JsonNetResult { Data = data, ContentType = contentType, ContentEncoding = contentEncoding, JsonRequestBehavior = behavior }; }

dot net core custom model binding for generic type parameters in mvc action methods

ⅰ亾dé卋堺 提交于 2020-01-05 05:51:53
问题 I am building a simple search, sort, page feature. I have attached the code below. Below are the usecases: My goal is to pass the "current filters" via each request to persist them particularly while sorting and paging. Instead of polluting my action method with many (if not too many) parameters, I am thinking to use a generic type parameter that holds the current filters. I need a custom model binder that can be able to achieve this. Could someone please post an example implementation? PS: I

Make HttpPost request to an action method in an ASP.NET MVC controller

浪尽此生 提交于 2019-12-23 05:15:08
问题 I am trying to build a functionality where I need to a create a candidate's profile in our application. There are two steps/UI's to create a candidate's profile: 1 - Create template...where the user enters candidate's information. 2 - Preview template...where the user will be shown a preview of how their profile would look like once they add the profile to our system. I have already created the views to support these UI's via a controller called "CandidateController" which contains few action

How should I return an Image from a controller action c# asp.net-mvc-2?

杀马特。学长 韩版系。学妹 提交于 2019-12-22 06:48:12
问题 I am building images from a byte[] like below. public FileContentResult GetEmployeeImage(int empId) { MemoryStream ms = new MemoryStream(byteArray); Image returnImage = Image.FromStream(ms); return returnImage;//How should i return this image to be consumed by javascript. } I want to return this image to the browser via a controller action method, so as it can be consumed by my javascript code and displayed in the browser. How should I do this? 回答1: You don't need to create an image object;

Handling 2 buttons submit Actions in a single View/Form - ASP.NET MVC 2 RTM

人盡茶涼 提交于 2019-12-19 04:07:13
问题 I have a View in which the user is able to upload a file to the server. In this view I also have 2 buttons: one to Upload a file and other to Download the last file imported. In my Controller I created 2 action methods: Import and Export. How could I manage to redirect each button click to the proper action method in my Controller? I have tried Html.ActionLink: <%= Html.ActionLink("Upload", "Import", "OracleFile")%> <%= Html.ActionLink("Download", "Export", "OracleFile")%> Html.ActionLink

ASP .NET MVC NonAction meaning

白昼怎懂夜的黑 提交于 2019-12-18 18:37:13
问题 Can anybody please tell me why should I use NonAction? I mean say I have a form with several submit values: Update, Delete or Insert. Since all the submit buttons have the same form in common I'm switching the submit value inside the controller and act accordingly. Like this: public ActionResult asd(string submitButton){ switch(submitButton){ case "Insert": return Insert(); // bla bla bla } } [NonAction] public ActionResult Insert(){ // some code inside here return View(); } Once again, why

How to receive JSON as an MVC 5 action method parameter

我怕爱的太早我们不能终老 提交于 2019-12-17 03:01:54
问题 I have been trying the whole afternoon crawling through the web trying to receive a JSON object in the action controller. What is the correct and or easier way to go about doing it? I have tried the following: 1: //Post/ Roles/AddUser [HttpPost] public ActionResult AddUser(String model) { if(model != null) { return Json("Success"); }else { return Json("An Error Has occoured"); } } Which gave me a null value on my input. 2: //Post/ Roles/AddUser [HttpPost] public ActionResult AddUser

Ambiguous action methods in MVC 2

有些话、适合烂在心里 提交于 2019-12-11 03:53:23
问题 I'm having some problems with ambiguous action methods in MVC 2. I've tried implementing the solution found here: ASP.NET MVC ambiguous action methods, but that simply gives me a "The resource cannot be found" error as it thinks I'm trying to invoke the action method I don't want to invoke. The RequiredRequestValueAttribute class I'm using is the exact same one as what was in the other question's solution: public class RequireRequestValueAttribute : ActionMethodSelectorAttribute { public

Implementing Routes for dynamic actions in MVC 4.0

落花浮王杯 提交于 2019-12-10 09:46:32
问题 Is it possible to define a route in MVC that dynamically resolves the action based on part of the route? public class PersonalController { public ActionResult FriendGroup() { //code } public ActionResult RelativeGroup() { //code } public ActionResult GirlFriendGroup() { //code } } I want to implement a routing for my Group Action Method below Url: www.ParlaGroups.com/FriendGroup www.ParlaGroups.com/RelativeGroup www.ParlaGroups.com/GirlFriendGroup routes.MapRoute( "Friends", "/Personal/

Disable action method from being called from the address bar

痴心易碎 提交于 2019-12-06 22:01:21
问题 I have a method in my controller that I don't want to be called from the address bar in the browser... Is there a way to do that? Maybe some kind of annotation, modification in the route configuration? Which are my options? 回答1: If you are going to use this action only from within your controller or Views then you can use ChildActionOnly attribute. If you want to access it using POST then you can use [HttpPost] attribute. But if you wish to use it using GET (i.e. using AJAX call etc) and don