【发布时间】:2017-01-18 17:10:13
【问题描述】:
所以,我在控制器中有 20 多个 Actions,如下所示:
public ActionResult DoThis()
{
Image img = Image.FromFile("DoThis.png");
//some other stuff to be done.
return View();
}
public ActionResult DoThat()
{
Image img = Image.FromFile("DoThat.png");
//some other stuff to be done.
return View();
}
我有一个视图,我想为放置在控制器中的每个动作显示ActionLink,并为动作分配图片,可以这样说:
@foreach
{
<div class="col-sm-4">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<img src="the image assigned to the controller actions" alt="" />
<h3 style="font-family:'Myriad عربي'">Action Name ؟</h3>
<a href="@URL.Action("The acion link from controller")" class="btn btn-default add-to-cart">Click Here</a>
</div>
</div>
</div>
</div>
}
这是可能的还是我要求太多了?
【问题讨论】:
-
<a href="@Html.ActionLink(...没有意义(ActionLink()生成一个<a>标记 - 我假设您的意思是Url.Action(...)? -
您总是可以使用反射来获取控制器中每个方法的名称。不太清楚你想做什么,为什么?为什么不创建一个包含方法属性和关联图像的项目集合?
-
我只想在控制器中动态添加指向我的操作的链接。我的意思是我不想为视图中控制器中的每个操作写
@URL.Action。那可能吗?有时,我的控制器中的这些操作的数量可能会增加或减少,在我看来应该自动处理。 -
@StephenMuecke 我有一个问题没有得到解答,请您看一下并发表您的观点,因为我需要解决这个问题。谢谢你。这是问题的链接。 Question
标签: c# asp.net-mvc