English 中文(简体)
Is using URL query string variables still RESTful
原标题:

I m presented with a problem of using query string variables in a RESTful Asp.net MVC application. Does that violate the RESTful pattern?

The thing is that Asp.net MVC uses default route like:

/controller/action/id

I have to pass through another controller+action combination like:

/controller/action/id/controllerX/actionX

but this won t work if I d be in the root of my application, because the first three parameters will be omitted and the last two will be treated as the first couple.

Instead of this I m tempted to use this notation instead:

/controller/action/id?Param=controllerX/actionX

Which would also work on root

http://domain/?Param=controllerX/actionX

But is this RESTful?

A bit of an explanation

I want to have a more modular approach to my views than the normal built-in with PartialViews. Because if I have a partial view that gets displayed on many pages I have to add vide data for that particular partial view in every single controller action that returns a view that uses that particular partial view. And I think that s a wrong way of doing things. Controllers become dependant on partial views that may (or god forbid may not ) be part of the main view.

rendering actions instead of partial views come to the rescue. I use my own Html.RenderAction() that calls into some controller s action that prepares its own data only. Great this works fine.

First problem was with HTTP method that got propagated to all RenderAction actions. So I changed it and I can control HTTP method as I like. Some actions may always be using GET no matter if the main view was posted back (thus using POST).

The problem is when these actions return partial views with their own FORM elements. Since my sub actions can t be directly posted to (because they wouldn t know which view to return) they actually post to the view instead. All sub actions with forms usually have propagated HTTP method from the main view, so they will actually enter postback action execution.

The thing is that only the actual form that was being posted back should execute its POST action. Others should just use GET method. Here s where my second controller/action pair comes into play. Every sub action form posts back to

mainViewController/action/?PostForm=controller/action

where the second parameter helps deciding which sub action rendering should propagate POST method to it. That particular form will be validated as defined in its post action.

I hope this explains my problem a bit more with a concrete example. This problem is related to my yesterday s question.

最佳回答

If this URL will result in the same view returned without dependence on session or cookies or the previous browsing history of a client, then yes, it will be what you call RESTful.

问题回答

暂无回答




相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签