Hi @Kenneth Tillman ,
- Do you want to use WebGird on the view and write code in VB? I wrote an example, you can refer to it.
- The example uses the EF framework to process the database.
2.WebGrid has many properties that can be set. In the example, I only set some properties. You can hover the mouse cursor on the methods, visual studio will gather suggestions for you.
- The example uses the EF framework to process the database.
- There are indeed many tutorials that use C# to write code.I found a tutorial on MVC 5 with EF 6 in Visual Basic, which can help you.
- In addition, you can also click this link to view a detailed explanation of MVC and VB.net.
2.When you have read the explanations in these two links, you can better understand the examples I provided.
- In addition, you can also click this link to view a detailed explanation of MVC and VB.net.
- You can use this code converter to convert most of the C# code into VB code.
DailyMVCDemoVBContext.vb
TestModel.vb Namespace ModelsNamespace Models Public Class DailyMVCDemoVBContext Inherits DbContext ' Your context has been configured to use a 'DailyMVCDemoVB' connection string from your application's ' configuration file (App.config or Web.config). By default, this connection string targets the ' 'DailyMVCDemoVB.DailyMVCDemoVB' database on your LocalDb instance. ' ' If you wish to target a different database and/or database provider, modify the 'DailyMVCDemoVB' ' connection string in the application configuration file. Public Sub New() MyBase.New("name=DailyMVCDemoVBContext") End Sub Public Property TestModels As DbSet(Of TestModel) ' Add a DbSet for each entity type that you want to include in your model. For more information ' on configuring and using a Code First model, see http:'go.microsoft.com/fwlink/?LinkId=390109. ' Public Overridable Property MyEntities() As DbSet(Of MyEntity) End Class End Namespace
Public Class TestModel
Public Property Id As Integer
Public Property Content As String
End Class
End Namespace
HomeController.vb Imports DailyMVCDemoVB.Models Public Class HomeController
Inherits System.Web.Mvc.Controller
Public db As DailyMVCDemoVBContext = New DailyMVCDemoVBContext()
Function Index() As ActionResult
Dim result = db.TestModels.ToList()
Return View(result)
End Function
End Class
Index.vbhtml @Code
ViewData("Title") = "Home Page"
End Code
@ModelType IEnumerable(Of DailyMVCDemoVB.Models.TestModel)
@Code
Dim grid = New WebGrid(Model, canPage:=True, rowsPerPage:=2)
grid.Pager(WebGridPagerModes.All)
End Code
@grid.GetHtml(tableStyle:="table table-bordered",
headerStyle:="header",
alternatingRowStyle:="alt", selectedRowStyle:="select",
columns:=grid.Columns(grid.Column("Id", "Id"), grid.Column("Content", "Content")))
**Here is the result. **
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
YihuiSun