How do you write out the action for an element I've tried to do
你如何写出我试图做的元素的动作
data-yes="@{Url.Action("DeleteAndAppend", "DepartmentsController", new { id = item.DepartmentId });}" but I always getting nothing
and tried this also and I'm not getting the out put of the action or path
并尝试了这一点,我没有得到行动或路径的输出
data-yes="@{Html.Action("DeleteAll", new { id = item.DepartmentId });}"
I just want the path of the action and the controller with the id output Does anyone know how to do this
我只想要动作的路径和带有id输出的控制器有没有人知道如何做到这一点
2 个解决方案
#1
2
First off, you should not use @{}, this syntax is used for executing code that doesn't actually output anything to the rendered view.
首先,您不应该使用@ {},此语法用于执行实际上不向渲染视图输出任何内容的代码。
Simply write
简单写一下
data-yes="@Url.Action(...)"
The Razor engine will know that the C# code ends at the closing parenthesis.
Razor引擎将知道C#代码在右括号处结束。
You can also use Url.RouteUrl:
您还可以使用Url.RouteUrl:
@Url.RouteUrl(new {controller= "Departments", action = "DeleteAndAppend", id = item.DepartmentId })
#2
2
Braces (@{}
) define a code block and the "output" (in this case just a return value) will be discarded. Note the fact that you've had to use a semicolon after the line.
大括号(@ {})定义一个代码块,“输出”(在这种情况下只是一个返回值)将被丢弃。请注意,您必须在行后使用分号。
Instead, I believe you wanted:
相反,我相信你想:
data-yes="@Url.Action("DeleteAndAppend", "DepartmentsController", new { id = item.DepartmentId })"
Yes, it's smart enough to figure out who the quotes belong to.
是的,它很聪明,可以弄清楚引用属于谁。
You could also use parentheses @()
if you want to be explicit:
如果要显式,也可以使用括号@():
data-yes="@(Url.Action("DeleteAndAppend", "DepartmentsController", new { id = item.DepartmentId }))"
This is particularly useful when you need to put text after a value, without a space between:
当您需要将值放在值之后,并且在以下位置之间没有空格时,这尤其有用:
<p>This is your @(Model.NumberOfVisits)th visit here!</p>
#1
2
First off, you should not use @{}, this syntax is used for executing code that doesn't actually output anything to the rendered view.
首先,您不应该使用@ {},此语法用于执行实际上不向渲染视图输出任何内容的代码。
Simply write
简单写一下
data-yes="@Url.Action(...)"
The Razor engine will know that the C# code ends at the closing parenthesis.
Razor引擎将知道C#代码在右括号处结束。
You can also use Url.RouteUrl:
您还可以使用Url.RouteUrl:
@Url.RouteUrl(new {controller= "Departments", action = "DeleteAndAppend", id = item.DepartmentId })
#2
2
Braces (@{}
) define a code block and the "output" (in this case just a return value) will be discarded. Note the fact that you've had to use a semicolon after the line.
大括号(@ {})定义一个代码块,“输出”(在这种情况下只是一个返回值)将被丢弃。请注意,您必须在行后使用分号。
Instead, I believe you wanted:
相反,我相信你想:
data-yes="@Url.Action("DeleteAndAppend", "DepartmentsController", new { id = item.DepartmentId })"
Yes, it's smart enough to figure out who the quotes belong to.
是的,它很聪明,可以弄清楚引用属于谁。
You could also use parentheses @()
if you want to be explicit:
如果要显式,也可以使用括号@():
data-yes="@(Url.Action("DeleteAndAppend", "DepartmentsController", new { id = item.DepartmentId }))"
This is particularly useful when you need to put text after a value, without a space between:
当您需要将值放在值之后,并且在以下位置之间没有空格时,这尤其有用:
<p>This is your @(Model.NumberOfVisits)th visit here!</p>