views:

38

answers:

2

how to create a asp.net mvc form helper that takes virtual directory into consideration?

In testing our dev server has:

http://devserver1/some_virt_directory/

production is:

http://www.example.com

I need the form post url to reflect if we have a virtual directory or not, is this possible?

A: 

You can use the UrlHelper.Content(..) method to resolve URLs taking into account what the real root is. The method will resolve the tilde ~ character. Look here for a related question on SO.

Hemme
A: 

The existing form helper methods already take into account this:

<% using (Html.BeginForm("actionName", "controllerName")) { %>
    ...
<% } %>
Darin Dimitrov