音乐商店2教程 - VB转换 [英] Music Store 2 Tutorial - VB Conversion
问题描述
我是新来asp.net和一直在努力通过教程 - 高达第10课,但是我不能让局部视图工作
I am new to asp.net and have been working through the tutorial - up to lesson 10, however I cannot get the partial view to work.
控制器: -
'GET:/我的购物/ CartSummary
Controller:- ' ' GET: /ShoppingCart/CartSummary
<ChildActionOnly()>
Public Function CartSummary() As ActionResult
Dim cart = ShoppingCart.GetCart(Me.HttpContext)
ViewData("CartCount") = cart.GetCount()
Return PartialView("CartSummary")
End Function
意见: -
CartSummary: -
Views:- CartSummary:-
@modeltype TEST.Cart
@Html.ActionLink("Cart (" & ViewData("CartCount") & ")", _
"Index", _
"ShoppingCart", _
New With {.id = "cart.GetCount"})
_layout: -
_Layout:-
<!DOCTYPE html>
<html>
<head>
<title>@ViewData("Title")</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
</head>
<body>
<div id="header">
<h1> ASP.NET MVC MUSIC STORE</h1>
<ul id="navlist">
<li class="first"><a href="@Url.Content("~")" id="current">Home</a></li>
<li><a href="@Url.Content("~/Store/")">Store</a></li>
<li>@Html.RenderAction("CartSummary", "ShoppingCart")</li>
<li><a href="@url.Content("~/StoreManager/")">Admin</a></li>
</ul>
</div>
<div id="main">
@RenderBody()
</div>
</body>
</html>
返回的错误是前pression不产生价值。
我可以删除标记,然后显示CartSummary。
The error returned is "Expression does not produce a value". I can remove the tag and then display the CartSummary.
感谢您的帮助。
推荐答案
如果你想在这里使用 Html.RenderAction
助手是正确的语法:
If you want to use the Html.RenderAction
helper here's the correct syntax:
@Code
@Html.RenderAction("CartSummary", "ShoppingCart")
End Code
或者,如果你preFER一个班轮:
Or if you prefer a one-liner:
@Code @Html.RenderAction("CartSummary", "ShoppingCart") End Code
如果你想使用的 Html.Action
辅助这是语法:
@Html.Action("CartSummary", "ShoppingCart")
对比度这两个与他们的C#等价:
Contrast those two with their C# equivalents:
@{Html.RenderAction("CartSummary", "ShoppingCart");}
@Html.Action("CartSummary", "ShoppingCart")
作为VB.NET的家伙,你可能会发现下面的文章有用的。
这篇关于音乐商店2教程 - VB转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!