Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 “System.Web.MVC.MvcHtmlString”类型的MVC错误(Razor)值无法转换为“Integer”_Asp.net Mvc 3_Razor - Fatal编程技术网

Asp.net mvc 3 “System.Web.MVC.MvcHtmlString”类型的MVC错误(Razor)值无法转换为“Integer”

Asp.net mvc 3 “System.Web.MVC.MvcHtmlString”类型的MVC错误(Razor)值无法转换为“Integer”,asp.net-mvc-3,razor,Asp.net Mvc 3,Razor,我得到以下错误 无法将“System.Web.Mvc.MvcHtmlString”类型的值转换为“Integer”。 在…上 @Html.ActionLinkedit,编辑,用户,使用{.id=Model.id}新建,无 这是密码 @If (Model.isUserMatch) Then @<div> @Html.ActionLink("edit", "Edit", "Users", New With {.id = Model.ID})

我得到以下错误

无法将“System.Web.Mvc.MvcHtmlString”类型的值转换为“Integer”。 在…上 @Html.ActionLinkedit,编辑,用户,使用{.id=Model.id}新建,无

这是密码

    @If (Model.isUserMatch) Then
    @<div>
        @Html.ActionLink("edit", "Edit", "Users", New With {.id = Model.ID})
        | <a href="#" onclick="jQuery('#OpenID').dialog('open'); return false">manage openids</a></div>
    End If
有人知道为什么会这样吗

编辑: 有人问我viewmodel是什么样子的

Imports System.Linq
Imports UrbanNow.Core.Extensions
Namespace Domain
    Public Class UserViewModel
        Public Property UserName As String
        Public Property Email As String
        Public Property Website As String
        Public Property ID As Integer
        Public Property OpenIds As List(Of OpenID)
        Public Property UserAge As String
        Public Property About As String
        Public Property Slug As String
        Public Property LastSeen As String
        Public Property Region As String
        Public Property MemberSince As String
        Public Property Reputation As String
        Public Property isUserMatch As Boolean = False
        Private MarkDownSharp As MarkdownSharp.Markdown

        Public Sub New(ByVal user As User)
            Dim currentuser As Authentication.AuthUserData = Authentication.CustomAuthentication.RetrieveAuthUser
            MarkDownSharp = New MarkdownSharp.Markdown
            With MarkDownSharp
                .AutoHyperlink = False
                .AutoNewLines = True
                .EncodeProblemUrlCharacters = True
                .LinkEmails = True
                .StrictBoldItalic = True
            End With

            ''# We want to ensure that the user has a username, even if they
            ''# haven't set one yet. What this does is check to see if the
            ''# user.UserName field is blank, and if it is, it will set the
            ''# username to "UserNNNN" where NNNN is the user ID number.
            _UserName = If(Not user.UserName Is Nothing, user.UserName, "User" & user.ID.ToString)

            ''# Nothing fancy going on here, we're just re-passing the object from
            ''# the database to the View. No data manipulation!
            _Email = user.Email
            _Website = user.WebSite
            _ID = user.ID
            _MemberSince = user.MemberSince

            ''# Get's a list of all of the user's OpenID's
            _OpenIds = user.OpenIDs.ToList

            ''# Converts the users birthdate to an age representation
            _UserAge = user.BirthDate.ToAge ''# IE: 29

            ''# Because some people can be real ass holes and try to submit bad
            ''# data (scripts and shitè) we have to modify the "About" content in
            ''# order to sanitize it.  At the same time, we transform the Markdown
            ''# into valid HTML. The raw input is stored without sanitization in
            ''# the database.  this could mean Javascript injection, etc, so the
            ''# output ALWAYS needs to be sanitized.
            _About = Trim(Utilities.HtmlSanitizer.Sanitize(MarkDownSharp.Transform(user.About)))

            ''# Removes spaces from Usernames in order to properly display the
            ''# username in the address bar
            _Slug = Replace(user.UserName, " ", "-")

            ''# Returns a boolean result if the current logged in user matches the
            ''# details view of the user in question.  This is done so that we can
            ''# show the edit button to logged in users.
            _isUserMatch = If(currentuser.ID = user.ID, True, False)

            ''# Grabs the users last activity and formats it to a <time> tag
            ''# for use with the timeago jQuery plugin
            _LastSeen = user.ActivityLogs.Reverse.FirstOrDefault.ActivityDate

            ''# Formats the users reputation to a comma Deliminated number 
            ''#    IE: 19,000 or 123k
            _Reputation = user.Reputation.ToShortHandNumber


            ''# Get the name of the users current Region.
            _Region = user.Region.Region.FirstOrDefault
        End Sub

    End Class
End Namespace

啊,我的继承权错了

我有

@Inherits System.Web.Mvc.ViewPage(Of MyApp.Core.Domain.User)
当我应该使用

@ModelType MyApp.Core.Domain.User

我没有看到这个错误。你的模型看起来像什么?它是一个视图模型-请参见编辑。当我使用MVC2和WebForms视图引擎时,一切都按预期工作。这是迁移到MVC3和Razor的过程,这让我很反感。我只是简单地修改了现有视图,将它们从一个视图移动到另一个视图。Razor页面的基本类型是System.Web.Mvc.WebViewPage。或者,正如您所发现的,您可以只使用@ModelType关键字。