我正在使用该方法构建一个url:
Url.Action("action", "controller");
Run Code Online (Sandbox Code Playgroud)
我喜欢将当前请求的查询字符串传递给该URL.像下面的东西(但它不起作用):
Url.Action("action", "controller", Request.QueryString);
Run Code Online (Sandbox Code Playgroud)
可以使用以下扩展名将QueryString转换为routevalues:
public static RouteValueDictionary ToRouteValues(this NameValueCollection queryString)
{
if (queryString.IsNull() || queryString.HasKeys() == false) return new RouteValueDictionary();
var routeValues = new RouteValueDictionary();
foreach (string key in queryString.AllKeys)
routeValues.Add(key, queryString[key]);
return routeValues;
}
Run Code Online (Sandbox Code Playgroud)
使用扩展方法,以下工作正常:
Url.Action("action", "controller", Request.QueryString.ToRouteValues());
Run Code Online (Sandbox Code Playgroud)
还有其他更好的方法吗?谢谢
我有一个在服务器端生成的右对齐单元格的表.单元格中的每一行都是可选的,因此它包含在服务器端的if-then语句中.
示例html显示3列,其中第一列在Google Chrome中有问题.第2列和第3列是正确的,但很奇怪,因为除了换行符和空格之外,html是相同的.
当我们查看Google Chrome中的第一列时,您会发现单元格中每条线的右边距不对齐100%.
这些问题在Firefox或IE中不存在,仅在Google Chrome中存在.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" style="border: 1px solid #000000;">
<tbody>
<tr>
<td style="text-align: right;border: 1px solid #000000;">
<span>Not Ok in Google Chrome</span>
<br /><span id="C1">500.000,00 €</span>
<br /><span id="C2">166.666,67 €</span>
<br /><span id="C3">489.545,90 €</span>
</td>
<td style="text-align: right;border: 1px solid #000000;">
<span>Ok in Google Chrome</span><br />
<span id="D1">500.000,00 €</span><br />
<span id="D2">166.666,67 €</span><br />
<span id="D3">489.545,90 €</span>
</td>
<td style="text-align: right;border: …Run Code Online (Sandbox Code Playgroud) 活动语言是从URL确定的,然后设置在
Thread.CurrentThread.CurrentUICulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureInfo.Name);
Run Code Online (Sandbox Code Playgroud)
这样,从正确的资源文件中检索翻译.
在控制器上使用Async操作时,我们有一个后台线程,其中Thread.CurrentThread.CurrentUICulture设置回操作系统默认值.但是在后台线程中我们需要正确的语言.
我创建了一个TaskFactory扩展来将文化传递给后台线程,它看起来像这样:
public static Task StartNew(this TaskFactory taskFactory, Action action, CultureInfo cultureInfo)
{
return taskFactory.StartNew(() =>
{
Thread.CurrentThread.CurrentUICulture = cultureInfo;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureInfo.Name);
action.Invoke();
});
}
Run Code Online (Sandbox Code Playgroud)
这允许我在动作控制器中执行以下操作:
[HttpPost]
public void SearchAsync(ViewModel viewModel)
{
AsyncManager.OutstandingOperations.Increment();
AsyncManager.Parameters["task"] = Task.Factory.StartNew(() =>
{
try
{
//Do Stuff
AsyncManager.Parameters["viewModel"] = viewModel;
}
catch (Exception e)
{
ModelState.AddModelError(string.Empty, ResxErrors.TechnicalErrorMessage);
}
finally
{
AsyncManager.OutstandingOperations.Decrement();
}
}, Thread.CurrentThread.CurrentUICulture);
}
public ActionResult SearchCompleted(Task task, ViewModel viewModel)
{
//Wait for the main …Run Code Online (Sandbox Code Playgroud) 通过定义实现IContactBehavior和IWsdlExportExtension的属性并在服务合同上设置该属性,您可以轻松地将Soap Headers添加到wsdl(有关更多信息,请参阅http://wcfextras.codeplex.com/)
但是现在我需要在所有Operationcontracts的wsdl中设置Soap Header合约,这次我不能设置属性.
以下代码(从IWsdlExportExtension.ExportEndPoint调用)不起作用,但在从SoapHeaderAttributes调用时执行(执行IWsdlExportExtension.ExportContract)
foreach (OperationDescription operationDescription in context.ContractConversionContext.Contract.Operations)
{
AddSoapHeader(operationDescription, "SomeHeaderObject", typeof(SomeHeaderObject), SoapHeaderDirection.InOut);
}
internal static void AddSoapHeader(OperationDescription operationDescription, string name, Type type, SoapHeaderDirection direction)
{
MessageHeaderDescription header = GetMessageHeader(name, type);
bool input = ((direction & SoapHeaderDirection.In) == SoapHeaderDirection.In);
bool output = ((direction & SoapHeaderDirection.Out) == SoapHeaderDirection.Out);
foreach (MessageDescription msgDescription in operationDescription.Messages)
{
if ((msgDescription.Direction == MessageDirection.Input && input) ||
(msgDescription.Direction == MessageDirection.Output && output))
msgDescription.Headers.Add(header);
}
}
internal static MessageHeaderDescription GetMessageHeader(string …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×1
asynchronous ×1
c# ×1
css ×1
cultureinfo ×1
html ×1
html-table ×1
right-align ×1
wcf ×1
wsdl ×1