我发现了一些文章如何在ASP.NET中将视图返回到字符串,但无法转换为能够使用.NET Core运行它
public static string RenderViewToString(this Controller controller, string viewName, object model)
{
var context = controller.ControllerContext;
if (string.IsNullOrEmpty(viewName))
viewName = context.RouteData.GetRequiredString("action");
var viewData = new ViewDataDictionary(model);
using (var sw = new StringWriter())
{
var viewResult = ViewEngines.Engines.FindPartialView(context, viewName);
var viewContext = new ViewContext(context, viewResult.View, viewData, new TempDataDictionary(), sw);
viewResult.View.Render(viewContext, sw);
return sw.GetStringBuilder().ToString();
}
}
Run Code Online (Sandbox Code Playgroud)
假设能够使用以下控制器从控制器调用:
var strView = this.RenderViewToString("YourViewName", yourModel);
Run Code Online (Sandbox Code Playgroud)
当我尝试将上述内容运行到.NET Core时,我遇到了很多编译错误.
我试图将其转换为使用.NET Core,但失败了,任何人都可以帮助提及所需的using ..和所需"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.1.0",
...
},的project.json.
其他一些示例代码在这里, …
我正在开发一个Asp.NET项目,我正在尝试使用text属性设置下拉列表的选定值.例如,我有一个带有文本的下拉列表中的项目test.我可以selecteditem通过编程方式将其设置为Text?我正在使用以下代码,但无法正常工作.
protected void Page_Load(object sender, EventArgs e)
{
string t = "test";
drpFunction.Text = t;
}
Run Code Online (Sandbox Code Playgroud)
但是没有用.有什么建议 ?
我有一个通过System.Drawing动态生成的图像.然后我将生成的图像输出到MemoryStream存储到我的Azure blob中.
但我似乎无法将我的文件存储在我选择的blob中.没有错误发生,我的图像成功保存到MemoryStream.正如所料,我的blob是空的.
我确保我的blob容器具有公共读/写访问权限.
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(String.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue("CMSAzureAccountName").ToString(), Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetConfigurationSettingValue("CMSAzureSharedKey").ToString()));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve reference to a previously created container.
CloudBlobContainer container = blobClient.GetContainerReference("myimagecontainer");
// Retrieve reference to a blob named "myblob".
CloudBlockBlob blockBlob = container.GetBlockBlobReference("test.jpg");
//Output image
ImageCodecInfo[] Info = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders();
EncoderParameters Params = new System.Drawing.Imaging.EncoderParameters(1);
Params.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
System.IO.MemoryStream msImage = new System.IO.MemoryStream();
GenerateImage.Render(imageOutput).Save(msImage, Info[1], Params); //GenerateImage.Render() …Run Code Online (Sandbox Code Playgroud) 我对Windows Phone更新鲜.我正在使用Windows Phone 7.1.我参与了Bing地图控制.
但我想知道有没有可能获得谷歌手机的谷歌地图api键.
如果有任何解决方案,请告诉我.
我有一个返回FileResult(这是一个png图像)的动作.我非常希望浏览器缓存结果,因为对于给定的请求uri它不会改变.
我使用路由来使uri看起来像这样 -
http://localhost:6094/Map/Tiles/1.0.0/none/2/5/5.png
Run Code Online (Sandbox Code Playgroud)
在动作方法中,我打电话: -
Response.Cache.SetCacheability(HttpCacheability.Public);
Run Code Online (Sandbox Code Playgroud)
在Fiddler,我可以看到答案有: -
Cache-control: public
Run Code Online (Sandbox Code Playgroud)
头.然而,对相同地图图块的后续请求如下所示: -
GET http://localhost:6094/Map/Tiles/1.0.0/none/2/5/5.png HTTP/1.1
Host: localhost:6094
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.34 Safari/536.11
Accept: */*
Referer: http://localhost:6094/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Run Code Online (Sandbox Code Playgroud)
因此导致200响应和数据传输.
知道为什么Chrome不打算缓存我的数据吗?
谢谢
滑
我正在使用Azure搜索索引创建产品的多面搜索。我大约有5个方面可帮助筛选显示的产品列表。
我注意到的一件事是,如果列出了很多要使用构面进行筛选的产品,则属于构面内的较小搜索项不会从索引中返回。
例如(简单起见),如果我的索引中以下方面列出了以下汽车制造商:
我发现斯柯达将不会退货,因为与该制造商链接的搜索结果很少。
当我使用以下查询直接在Azure门户中搜索索引时,可以看到这种情况: facet=<facet-field-name>
经过研究,我遇到了以下解释:
由于分片架构,构面计数可能不准确。每个搜索索引都有多个分片,每个分片均按文档计数报告前N个方面,然后将其合并为一个结果。如果某些分片具有许多匹配值,而其他分片具有更少的匹配值,则您可能会发现结果中某些构面值缺失或计数不足。
尽管此行为可以随时更改,但是如果您今天遇到此行为,则可以通过人为地夸大count:到较大数量以强制每个分片执行完整报告来解决此问题。如果count:的值大于或等于字段中唯一值的数量,则可以保证得到准确的结果。但是,当文档计数很高时,会降低性能,因此请谨慎使用此选项。
基于以上引用,我如何人为地增加计数以解决此问题?还是有人知道更好的方法?
我发现了一个女巫的例子我对asp.net webforms中的内容并不了解.这个例子是使用详细信息视图控件制作的.这是代码:
<InsertItemTemplate>
<asp:DropDownList ID=”DropDownList1” runat=”server”
DataSourceID=”GenresDataSource“ DataTextField=”Name” DataValueField=”Id”
SelectedValue=’<%# Bind(“GenreId”) %>’>
</asp:DropDownList>
</InsertItemTemplate>
Run Code Online (Sandbox Code Playgroud)
在下拉列表中,我理解:
如果我在顶部说的是真的,那么在GenreId是数据库中的列的情况下,该语句会产生什么:
<%# Bind(“GenreId”) %>’
Run Code Online (Sandbox Code Playgroud) asp.net ×7
c# ×3
azure ×2
.net-core ×1
asp.net-core ×1
asp.net-mvc ×1
c#-4.0 ×1
razor ×1
windows ×1