表达式不会收到值。使用vb.net中的html.renderpartial()不确定正确的剃刀代码

时间:2016-06-28 08:02:25

标签: asp.net-mvc vb.net razor

我正在学习mvc asp.net并遵循教程http://www.codeproject.com/Articles/866143/Learn-MVC-step-by-step-in-days-Day

这是在C#和我在vb.net编码。

我无法在线找到解决方案。我被卡住了。

@For Each employee As MvcApplication1.EmployeeViewModel In Model.Employees
      @<tr>
      <td>@employee.EmployeeName</td>
      <td style="background-color:@employee.SalaryColor">@employee.Salary</td>   
      </tr>

   Next employee

   </table>

</div>
@*tried using this*@

 @Html.RenderPartial("Footer", Model.FooterData)

 @*tried using this as well*@

@Code
    @Html.RenderPartial("Footer", Model.FooterData)
End Code

这是我的EmployeeListViewModel

中的代码
Public Class EmployeeListViewModel
    Public Property Employees As List(Of EmployeeViewModel)
    Public Property UserName As String
    Public Property FooterData As FooterViewModel
End Class

EmployeeController索引操作方法

Function Index()As ActionResult

        Dim elvm As EmployeeListViewModel = New EmployeeListViewModel()
        Dim empBL As EmployeeBusinessLayer = New EmployeeBusinessLayer
        Dim employees As List(Of Employee) = empBL.GetEmployees()
        Dim evms As List(Of EmployeeViewModel) = New List(Of EmployeeViewModel)
        elvm.UserName = User.Identity.Name
        elvm.FooterData = New FooterViewModel
        elvm.FooterData.CompanyName = "Sample Company"
        elvm.FooterData.Year = DateTime.Now.Year.ToString()
        For Each emp As Employee In employees
            Dim evm As EmployeeViewModel = New EmployeeViewModel
            evm.EmployeeName = emp.FirstName + " " + emp.LastName
            evm.Salary = String.Format("{0:C}", emp.Salary)
            If emp.Salary > 300 Then
                evm.SalaryColor = "pink"
            Else
                evm.SalaryColor = "green"
            End If
            evms.Add(evm)
        Next (emp)
        elvm.Employees = evms
        Return View("Index", elvm)

    End Function

FooterViewModel

Public Class FooterViewModel
    Public Property CompanyName() As String
    Public Property Year() As String
End Class

Footer.vbhtml

@modeltype MvcApplication1.FooterViewModel
<div style="text-align:right;background-color: silver;color:Navy;border: 1px solid gray;margin-top:2px;padding-right:10px;">
@Model.CompanyName &copy; @Model.Year
</div>

2 个答案:

答案 0 :(得分:0)

正确的语法是

 @{Html.RenderPartial("_Comments");}

您可以直接提供您的观看名称

答案 1 :(得分:0)

使用

 @Code
   Html.RenderPartial("Footer", Model.FooterData)
 End Code

  @Code
   @Html.RenderPartial("Footer", Model.FooterData)
  End Code