我想在视图中单击按钮后生成一个动态 Html.Action 链接。目前我正在使用 ajax 来更新
使用从数据库中随机生成的产品名称在表单上进行标记。我的代码如下所示:
<p>
<%using (Ajax.BeginForm("RandomProductName", new AjaxOptions { UpdateTargetId = "result" }))
{ %>
<input type="submit" value="Generate Random Product"/>
<% } %>
</p>
<p id="result"></p>
控制器中的“RandomProductName”方法返回产品类型的字符串值。我希望能够将其转换为类似于 <%=Html.ActionLink("Pliers", "Details", new {id = "2"})%> 的动态 Html.Action 链接以显示详细信息视图。
任何对此的帮助将不胜感激,因为我这个周末刚刚学习了这个框架。
更新:这是我当前方法的代码:
public PartialViewResult RandomProductLink()
{
int id = RandomProductID();
Product product = GetProduct(id);
return PartialView(Product.Name);
//i think i need to return something like - <%= Html.ActionLink(Product.Name, "Details" new {id=Product.ID})%>
}