actionmethod

How can I specify a namespace when calling @Html.Action(…) in ASP.NET MVC

泄露秘密 提交于 2019-12-06 01:54:27
问题 When I try to use Html.Action in ASP.NET MVC 3 for a controller in a different namespace from the current controller I get an error : Code: @Html.Action("Foo", "Application", new { id = "FG2" }) Error : The controller for path '/rrmvc/store/checkout' was not found or does not implement IController. This error only occurs when the controller ApplicationController is in a different NAMESPACE from the current controller such as StoreControllers.CheckoutController (in fact they're in completely

Implementing Routes for dynamic actions in MVC 4.0

丶灬走出姿态 提交于 2019-12-05 21:34:45
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/{Friend}Group", new { controller = "Personal", action = "{Friend}Group" } ); routes.MapRoute( "Friends", "

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

笑着哭i 提交于 2019-12-05 09:41:06
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? You don't need to create an image object; you just want to return the raw data. The browser will read the raw data into an image. return File(byteArray

ASP.NET MVC: How to covert an ActionResult to string?

蹲街弑〆低调 提交于 2019-12-04 11:06:30
问题 I would like to take an existing action method, render its return value to a string and ship it as a JSON for a response to an AJAX request. To do this, I need to render an ActionResult to a string. How do i do this? We have the opposite where we can convert a string to an ActionResult by using this.Content(). Update The existing and 1st action method returns a type ActionResult but it really returns a ViewResult to respond to HTTP post request. I have a 2nd action method (my facade) that

Keeping a controller thin (too many action methods)

廉价感情. 提交于 2019-12-03 06:49:56
问题 I'm working on my first real ASP.NET MVC project and I've noticed that the controller I've been working in is getting rather large. This seemingly goes against the best practice of keeping your controllers thin. I've done a good job keeping the business logic out of the controllers. I use a separate layer for that. Each action primarily calls a method in the business layer and coordinates the end result based on whether or not the modelstate is valid. That said, the controller has a large

Keeping a controller thin (too many action methods)

情到浓时终转凉″ 提交于 2019-12-02 20:28:44
I'm working on my first real ASP.NET MVC project and I've noticed that the controller I've been working in is getting rather large. This seemingly goes against the best practice of keeping your controllers thin. I've done a good job keeping the business logic out of the controllers. I use a separate layer for that. Each action primarily calls a method in the business layer and coordinates the end result based on whether or not the modelstate is valid. That said, the controller has a large number of action methods. Intuitively, I would like to break the controller down into sub-controllers but

ajax call results in error instead of succes

风流意气都作罢 提交于 2019-12-02 05:55:11
问题 In my ASP.net mvc3 project, i use a ajax call to send json data to a create actionmethod in the controller Company. But when i debug the ajax call, it always end up in a error result instead of the succes result. ajax call: $.ajax({ url: '/Company/Create', type: 'POST', data: JSON.stringify(CreateCompany), dataType: 'Json', contentType: 'application/json; charset=utf-8', success: function () { alert('ajax call successful'); }, error: function () { alert('ajax call not successful'); } }); My

ajax call results in error instead of succes

北城余情 提交于 2019-12-02 01:41:21
In my ASP.net mvc3 project, i use a ajax call to send json data to a create actionmethod in the controller Company. But when i debug the ajax call, it always end up in a error result instead of the succes result. ajax call: $.ajax({ url: '/Company/Create', type: 'POST', data: JSON.stringify(CreateCompany), dataType: 'Json', contentType: 'application/json; charset=utf-8', success: function () { alert('ajax call successful'); }, error: function () { alert('ajax call not successful'); } }); My action method in the Company controller : [HttpPost] public ActionResult Create (Company company) { try

ASP.NET MVC: Enforce AJAX request on an action

跟風遠走 提交于 2019-11-30 18:18:40
I'm looking for a way to enforce a controller's action to be accessed only via an AJAX request. What is the best way to do this before the action method is called? I want to refactor the following from my action methods: if(Request.IsAjaxRequest()) // Do something else // return an error of some sort What I'm envisioning is an ActionMethodSelectorAttribute that can be used like the [AcceptVerbs] attribute. I have no experience crating such a custom attribute though. bmancini Create an ActionFilter that fires OnActionExecuting public class AjaxActionFilter : ActionFilterAttribute { public

Is it better to return the most specific or most general type from an action method? [closed]

这一生的挚爱 提交于 2019-11-30 16:56:49
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed last year . What are the benefits or detriments of either? 回答1: My guidelines has always been most specific out, and most general in. The more general your data type is, the less the code that uses it knows about the data type. For instance, if a method returns a collection, I would return