无法从控制器访问模型数据 [英] can't access model data from controller
问题描述
在models文件夹中添加movie.cs并在web.config文件中添加连接字符串之后.我尝试从控制器访问模型数据,但代替了选择模型类:在创建控制器时,模型类不显示吗?
在创建controller
After adding a movie.cs inside models folder and added connection string in web.config file . i tried to access model data from controller but in place of chooosing model class: while creating controller that model class donot shows up?
is there any steps i have to do before creating controller
推荐答案
右键单击controller(folder)->之前,我必须执行任何步骤吗?单击添加引用->单击项目选项卡->然后选择保存movie.cs文件的文件夹.
试试这个,告诉我结果如何.
Right click on controller(folder) -> click on Add Reference -> click on project tab -> and select folder in which your movies.cs file is kept.
Try this and tell me whatever the result will be..
首先在控制器中添加模型参考:
例如:
First add a reference for model in the controller :
ex:
using MVCapplication1.Models;
这里的MVCapplication1是应用程序名称,并确保要访问的类位于Models文件夹下.
然后创建模型类的实例,使用该实例的点属性名即可访问.
试试这个
here MVCapplication1 is the application nameand be sure that the class you want to access is present under Models folder.
then create an instance of the model class, using the instance dot property name can be accessed.
try this
这篇关于无法从控制器访问模型数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!