controller-action

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

ASP.NET MVC: Enforce AJAX request on an action

可紊 提交于 2019-11-30 02:37:53
问题 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. 回答1: Create an

Rails: Custom nested controller actions

心已入冬 提交于 2019-11-29 08:05:06
I want to setup a custom nested controller actions but I can't figure out the routing. I keep getting the following error No route matches [GET] "/assets" routes.rb resources :companies do resources :requests do match :accept end end index.html.rb <% @requests.each do |request| %> <ul class="users"> <li> <%= full_name(request.profile) %> <%= request.status %> <%= link_to "Accept", :controller => "requests", :action => "accept", :id => request.id %> </li> </ul> <% end %> There are a couple of problems: routing to the accept action and building a URL to a nested resource. Defining custom actions

How to serve html file from another directory as ActionResult

有些话、适合烂在心里 提交于 2019-11-28 07:12:21
I have a specialised case where I wish to serve a straight html file from a Controller Action. I want to serve it from a different folder other than the Views folder. The file is located in Solution\Html\index.htm And I want to serve it from a standard controller action. Could i use return File? And how do I do this? If you want to render this index.htm file in the browser then you could create controller action like this: public void GetHtml() { var encoding = new System.Text.UTF8Encoding(); var htm = System.IO.File.ReadAllText(Server.MapPath("/Solution/Html/") + "index.htm", encoding); byte[

Rails: Custom nested controller actions

纵然是瞬间 提交于 2019-11-28 01:38:25
问题 I want to setup a custom nested controller actions but I can't figure out the routing. I keep getting the following error No route matches [GET] "/assets" routes.rb resources :companies do resources :requests do match :accept end end index.html.rb <% @requests.each do |request| %> <ul class="users"> <li> <%= full_name(request.profile) %> <%= request.status %> <%= link_to "Accept", :controller => "requests", :action => "accept", :id => request.id %> </li> </ul> <% end %> 回答1: There are a

How to serve html file from another directory as ActionResult

笑着哭i 提交于 2019-11-27 01:45:53
问题 I have a specialised case where I wish to serve a straight html file from a Controller Action. I want to serve it from a different folder other than the Views folder. The file is located in Solution\Html\index.htm And I want to serve it from a standard controller action. Could i use return File? And how do I do this? 回答1: If you want to render this index.htm file in the browser then you could create controller action like this: public void GetHtml() { var encoding = new System.Text