Click here to Skip to main content
15,915,076 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys...
please help me.
i use vb.net 2015. and i want to make customehelper and i try use tagbuilder, but i can't found the tagbuilder.

i don't know why... please help me.

What I have tried:

VB
Imports System.Linq.Expressions
Imports System.Web.Mvc
Imports System.Web.Routing
Imports System.Runtime.CompilerServices
Imports System.Text

Public Class SpanFor
    Public Shared Function SpanFor(Of TModel, TProperty)(helper As HtmlHelper(Of TModel), expression As Expression(Of Func(Of TModel, TProperty)), Optional htmlAttributes As Object = Nothing) As MvcHtmlString
        Dim valueGetter = expression.Compile()
        Dim value = valueGetter(helper.ViewData.Model)

        Dim span As TagBuilder("span")
        span.MergeAttributes(New RouteValueDictionary(htmlAttributes))
        If value IsNot Nothing Then
            span.SetInnerText(value.ToString())
        End If

        Return MvcHtmlString.Create(span.ToString())
    End Function

End Class
Posted
Updated 16-Jan-17 17:48pm
Comments
Suvendu Shekhar Giri 16-Jan-17 23:27pm    
"but i can't found the tagbuilder"
not found, meaning? is it giving any error?
bejos3519 17-Jan-17 0:10am    
is not defined

1 solution

You need a few things:
1) You have to be using .NET Framework 4.x.

2) Add a reference to System.Web.WebPages.dll. If your already in a MVC project, this should already exist.

3) Add Imports System.Web.Mvc to the top of the file you are trying to use the class in, as you already are.
 
Share this answer
 
Comments
bejos3519 17-Jan-17 0:51am    
thanks sir... now i get the tagbuilder after i add reference "system.web.webpage.dll".
but i got a new trouble...

i can not get the value from this code,
Dim valueGetter = expression.Compile()
Dim value = valueGetter(helper.ViewData.Model)

the value of "helper.viewData.Model" = nothing. its make the error. my application be stop.

here my view :
@Html.SpanFor(Function(model) model.SHOECODE, "")

help me...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900