如何为ASP.NET MVC行动的URL,包括主机名和端口? [英] How to generate a URL for ASP.NET MVC action, including hostname and port?

查看:648
本文介绍了如何为ASP.NET MVC行动的URL,包括主机名和端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在的要求是:


  

http://www.mofeng.com:4355/


我要显示asp.net视图层的操作URL,URL是这样的(完整的URL包括的的http://协议 + 主机名 + 端口 + controllerName + actionName 的):


  

<一个href=\"http://www.mofeng.com:4355/controllerX/actionY\">http://www.mofeng.com:4355/controllerX/actionY



解决方案

  Url.Action(行动,控制器,空,Request.Url.Scheme);

如何,包括在窗体动作以下属性?


  

1。协议(http://或https://)结果
   2。主机名结果
   3。查询字符串结果
   4。端口


  @ {
    VAR actionURL = Url.Action(行动,控制器,
                               FormMethod.Post,Request.Url.Scheme)
                    + Request.Url.PathAndQuery;
}
@using(Html.BeginForm(动作,控制器,FormMethod.Post,
                                                   新{@Action = actionURL}))
{
}

My current request is:

http://www.mofeng.com:4355/

I want display an action url in asp.net view layer, url is like this(full url, including http://protocol + hostname + port + controllerName + actionName):

http://www.mofeng.com:4355/controllerX/actionY

解决方案

Url.Action("Action", "Controller", null, Request.Url.Scheme);

How to include the following in the Form Action attribute?

1. Protocol(http:// or https://)
2. HostName
3. QueryString
4. Port

@{
    var actionURL = Url.Action("Action", "Controller", 
                               FormMethod.Post, Request.Url.Scheme)  
                    + Request.Url.PathAndQuery;
}
@using (Html.BeginForm("Action", "Controller", FormMethod.Post, 
                                                   new { @action = actionURL }))
{
}

这篇关于如何为ASP.NET MVC行动的URL,包括主机名和端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆