I'm using the new Helper tags in ASP.NET MVC 6.
<form asp-area="DAS"
asp-controller="Report"
asp-action="Add"
asp-route-id="@Model.id"
asp-route-incBalance="@Model.incBalance"
asp-route-dateSet="@Model.dataStart.ToString("yyyy-MM-dd")"
asp-route-dateNext="@Model.dataEnd.ToString("yyyy-MM-dd")"
method="post" role="form">
</form>
I want to routing attribute:
asp-route-dateNext="@Model.dataEnd.ToString("yyyy-MM-dd")"
was applied only if:
{
if (Model.incBalance == 0)
{
asp-route-dateNext="@Model.dataEnd.ToString("yyyy-MM-dd")"
}
}
As a result, I want to get something like this:
<form asp-area="DAS"
asp-controller="Report"
asp-action="Add"
asp-route-id="@Model.id"
asp-route-incBalance="@Model.incBalance"
asp-route-dateSet="@Model.dataStart.ToString("yyyy-MM-dd")"
{
if (Model.incBalance == 0)
{
asp-route-dateNext="@Model.dataEnd.ToString("yyyy-MM-dd")"
}
}
method="post" role="form">
</form>
I get these errors:
TagHelper attributes must be well-formed.
if (Model.incBalance == 0)
and
The tag helper 'form' must not have C# in the element's attribute declaration area.
asp-route-dateNext="@Model.dataEnd.ToString("yyyy-MM-dd")"
I'm using Visual Studio 2015 Update 1
Update 1: I also tried this option:
@(Model.incBalance == 0 ? "asp-route-dateNext=" + Model.dataEnd.ToString("yyyy-MM-dd") : string.Empty)
But the error remained:
The tag helper 'form' must not have C# in the element's attribute declaration area.
@(Model.incBalance == 0 ? "asp-route-dateNext=" + Model.dataEnd.ToString("yyyy-MM-dd") : string.Empty)