嗨,我对Html.ActionLink有疑问.
想像:
@Html.ActionLink(item.title, "Singlet", new { id = item.blog_id })
Run Code Online (Sandbox Code Playgroud)
产生http:// [url]/[controller]/Singlet/[id]
但是,如果我想在最后添加一些更随意的数据呢?例如:
HTTP:// [URL]/[控制器] /背心/ [ID] /#评论
跳转到评论div.我知道我可以用以下内容自己制作字符串:
@( new HtmlString(String.Format("<a href=\"Blog/Singlet/{0}/#comments\">link to comments</a>", item.blog_id)) )
Run Code Online (Sandbox Code Playgroud)
但我希望有一种更清洁的方式,也许是使用ActionLink?
谢谢
我有兴趣使用具有QuerySting Attached的ASP.Net MVC 3创建URL但是在任何地方我看它都说我需要创建一个路由.有谁知道如何创建这个:
<a href="/home/search/1120000000?page=3">Next Page</a>使用Html.ActionLink帮助程序.
我正在尝试使用Ajax.Actionlink来呈现局部视图.但它只会将我重定向到局部视图.我还补充说:<add key="UnobtrusiveJavaScriptEnabled" value="true" />到webconfig.任何人?
我的layout.cshtml Scripts.render和脚本在head标签中.Ajax.actionlink和div在体内
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/Scripts/jqueries")
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
@Ajax.ActionLink("Ajax Click", "Document","Home", new AjaxOptions { UpdateTargetId = "result", InsertionMode = InsertionMode.Replace })
<div id="result">
</div>
Run Code Online (Sandbox Code Playgroud)
家庭控制器:
public PartialViewResult Document()
{
return PartialView("Document", om);
}
Run Code Online (Sandbox Code Playgroud)
我的Document.cshtml
@model mymodel
@foreach (var item in Model)
{
<li>@Html.ActionLink(item.something, "Controller", "Action")</li>
}
Run Code Online (Sandbox Code Playgroud) 我有一个果园项目,我在MVC中创建了一个模块.我想使用@ Html.ActionLink将特定用户的id传递给控制器,但它不会调用控制器.这是我的代码:
在视图中:
@Html.ActionLink("100111", "AddToCart", "ShoppingCart", new { id = 101 }, null)
//also tried,
@Html.ActionLink("102829", "AddToCart", "ShoppingCart", new { id = 1, area = "OnlineShopping" },null)
Run Code Online (Sandbox Code Playgroud)
在控制器中:
[HttpPost]
public ActionResult AddToCart(int id)
{
_shoppingCart.Add(id, 1);
return RedirectToAction("Index");
}
[Themed]
public ActionResult Index()
{
// Create a new shape using the "New" property of IOrchardServices.
var shape = _services.New.ShoppingCart();
// Return a ShapeResult
return new ShapeResult(this, shape);
}
Run Code Online (Sandbox Code Playgroud) 我有一个视图,其中我有一个Url.Action链接.当用户点击此链接时,我正在重定向到一个操作方法.当用户点击Url.Action链接时,我需要将viewbag传递给此方法,我需要在重定向的action方法中访问此viewbag值.
在视图中:
<a class="Border left " id="BackBtn"
href="@Url.Action("Search")">
<span>@Labels.BacktoQuesstions</span>
</a>
Run Code Online (Sandbox Code Playgroud)
在控制器中:
public ActionResult Search()
{
//Here I need to access the viewbag value from Url.Action method
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的建议!!
我在几乎空的ASP.NET MVC项目的Site.Master页面中有以下代码.
<li>
<%= Html.ActionLink("Home", "Index", "Home")%>
</li>
<li>
<%= Html.ActionLink("Feed List", "FeedList", "Home")%>
</li>
<li>
<%= Html.ActionLink("Monitored Feeds", "MonitoredFeeds", "Home")%>
</li>
<li>
<%= Html.ActionLink("About", "About", "Home")%>
</li>
Run Code Online (Sandbox Code Playgroud)
我还没有添加任何文件夹到名为Feeds的Views文件夹.在Feeds文件夹中,我有两个视图; FeedList.aspx和MonitoredFeeds.aspx.我还将以下代码添加到HomeController中,如下所示.
[HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
ViewData["Title"] = "The Reporter";
ViewData["Message"] = "Welcome to The Reporter.";
return View();
}
public ActionResult About()
{
ViewData["Title"] = "About Page";
return View();
}
public ActionResult FeedList()
{
ViewData["Title"] = "Feed List";
return View();
}
public ActionResult MonitoredFeeds()
{ …Run Code Online (Sandbox Code Playgroud) 我可以创建到另一个控制器的动作链接,并且该动作方法带有参数吗?
普通的动作链接是:
@ Html.ActionLink(“首页”,“索引”,“表1”)
并且如果我们有一个到控制器内部的动作方法的动作链接:
@ Html.ActionLink(“编辑”,“编辑”,新的{id = item.ID})
现在,如果我想转到另一个控制器内的动作方法的动作链接,该怎么办?它会是什么样子?
即有一个动作方法Action1在参数表2中有一个参数ParentID,我如何编写一个到该动作方法的动作链接?