VB syntax for declaring one model in MVC (for using strongly typed views)

I try to avoid using magic strings as much as I can, but I can't seem to find the correct syntax for VB to bind one model as shown in this C # example .

Can anyone point me in the right direction?

(currently below it says "expected end of statement" in the model text)

<% Dim FormObject As Form = (Form)Model %>

      

EDIT:

A simple transfer was necessary (sorry for the stupid question)

<%  Dim FormObject As Form = DirectCast(Model, Form)%>

      

+1


a source to share


2 answers


What you are trying to accomplish is a cast operator. Try the following code.



<% Dim FormObject As Form = DirectCast(Model, Form) %>

      

+2


a source


you need to make sure your view is strongly typed or you are using C # or VB.NET:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<FormObject>" %>

      



so when you want to use it you don't have to throw it

<% Dim FormObject As Form = Model %>

      

+1


a source







All Articles