我将要描述的问题与我已经发现的问题非常相似(例如这篇文章名称几乎相同),但我希望我能把它变成一个不重复的东西.
我在Visual Studio中创建了一个新的ASP.NET MVC 5应用程序.然后,我定义了两个模型类:
public class SearchCriterionModel
{
public string Keyword { get; set; }
}
public class SearchResultModel
{
public int Id { get; set; }
public string FirstName { get; set; }
public string Surname { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后我创建了SearchController如下:
public class SearchController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult DisplaySearchResults()
{
var model = new List<SearchResultModel>
{
new SearchResultModel { Id=1, FirstName="Peter", Surname="Pan" },
new SearchResultModel …Run Code Online (Sandbox Code Playgroud) 使用锚标记助手,我们如何View在新的浏览器窗口选项卡中打开ASP.NET Core MVC .我尝试了以下但首先它抱怨target属性也需要具有href属性.但是,正如我们所知,我们不能在asp-action属性中使用href属性MVC Core; 否则我们会得到如下所示的错误.注意:我已经看到了一些类似于他的建议,但它们与标签助手无关:
<a asp-action="testAction" href="#" target="_blank">Click Here</a>
Run Code Online (Sandbox Code Playgroud)
错误:
InvalidOperationException:无法覆盖'href'属性.具有指定'href'的属性不得具有以'asp-route-'开头的属性或'asp-action','asp-controller','asp-area','asp-route','asp-protocol' ,'asp-host'或'asp-fragment'属性.
目前尚不清楚正确的语法应该是什么,我已经尝试了一些示例,但没有运气,这是我当前可以工作的按钮代码,我需要它在单击时保持作为按钮在新窗口/新选项卡中打开操作
<input type="button" title="Read" value="@T("Account.DownloadableProducts.Read")" onclick="location.href='@Url.Action("GetDownload", "Download", new { orderItemId = Model.DownloadMappingIds[product.Id].guid })'" />
Run Code Online (Sandbox Code Playgroud)
谢谢