It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
6年前关闭。
我有一堂课
如何自动将该对象转换为urlencoded字符串,然后将其附加到我的主机名上?
Urlencoded字符串:
最后结果:
如果您想要一个绝对的URL,只需使用
6年前关闭。
我有一堂课
class Example
{
public int Prop1 { get; set; }
public int Prop2 { get; set; }
public String Prop3 { get; set; }
}
如何自动将该对象转换为urlencoded字符串,然后将其附加到我的主机名上?
Urlencoded字符串:
prop1=val1&prop2=val2&prop3=val3
最后结果:
http://example.com?prop1=val1&prop2=val2&prop3=val3
最佳答案
您可以使用UrlHelper
:
var model = new MyClass
{
Prop1 = 1,
Prop2 = 2,
Prop3 = "prop 3"
};
string url = Url.Action("index", "home", model);
// will generate /?Prop1=1&Prop2=2&Prop3=prop%203
如果您想要一个绝对的URL,只需使用
proper overload
:string url = Url.Action("index", "home", model, "http");
09-07 05:40