当前位置: 代码迷 >> VB Dotnet >> 烦劳大家看看小弟写的mvc是不是符合标准的
  详细解决方案

烦劳大家看看小弟写的mvc是不是符合标准的

热度:69   发布时间:2016-04-25 02:13:06.0
麻烦大家看看小弟写的mvc是不是符合标准的?
Models文件夹里的:
DiyModels.vb
Public Class DiyModels

    Public Property Id As Integer
    Public Property Name As String

End Class


SqlDB.vb
Imports System.Data.SqlClient

Public Class SqlDB

    Private db As String = ConfigurationManager.ConnectionStrings("DBConnection").ConnectionString

    Function GetVal()
        Dim connection As SqlConnection
        Dim command As SqlCommand

        Dim cmdString As String = "SQL存储过程"
        connection = New SqlConnection(db)
        command = New SqlCommand(cmdString, connection)
        connection.Open()
        Dim reader As SqlDataReader
        reader = command.ExecuteReader(CommandBehavior.CloseConnection)
        Dim DataList As New List(Of DiyModels)()
        While reader.Read()
            DataList.Add(New DiyModels With {.Name = reader("Name").ToString(), .Id = reader("Id").ToString()})
        End While
        Return DataList

    End Function

End Class



Controllers文件夹里的:
HomeController.vb
Public Class HomeController
    Inherits System.Web.Mvc.Controller

    Function Index() As ActionResult
        Dim aaa As New SqlDB
        Return View(aaa.GetVal)
    End Function
End Class



Views文件夹里的:
Index.aspx
<%@ Page Language="VB" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="Diy" %>
<asp:Content ID="indexContent" ContentPlaceHolderID="MainContent" runat="server">
    <ul>
        <%For Each row As DiyModels In ViewData.Model%>
            <li><a href="http://www.xxx.com/article/<%=row.Id%>"><%=row.Name%></a></li>
        <%Next%>
    </ul>
</asp:Content>


如果哪里有写得不对 或者有不足都希望请各位高手指出 谢谢
------解决方案--------------------
MVC是一个很自由的框架,没有标准一说。
  相关解决方案