我正在创建一个 MVC3 Internet 应用程序来从数据库中获取数据。
我收到以下错误:
Compiler Error Message: CS1061: 'System.Collections.Generic.IEnumerable<Project.Models.MyModel>' does not contain a definition for 'SId' and no extension method 'SId' accepting a first argument of type 'System.Collections.Generic.IEnumerable<Project.Models.MyModel>' could be found (are you missing a using directive or an assembly reference?)
这是我的代码:
控制器:
public ActionResult RetrievedData()
{
MyModel mymodel=new MyModel();
IEnumerable<MyModel> res = mymodel.RetrieveData();
return View();
}
模型:
public class MyModel
{
public int SId { get; set; }
public string StrName { get; set; }
public DateTime? DateCreated { get; set; }
Test_2Entities entity = new Test_2Entities();
public IEnumerable<MyModel> RetrieveData()
{
var query = (from s in entity.StudentInfo
where s.SId == 1
select new MyModel()
{
SId = s.SId,
StrName = s.SName,
DateCreated = s.DateCreated
});
return query.AsEnumerable();
}
看法:
@model IEnumerable<DateAndTimecontrol.Models.MyModel>
@Html.BeginForm("GetData", "Home", FormMethod.Get)
{
Time Picker:<input type="text" id="timepicker2" />
@Html.TextBoxFor(m=>m.SId,"",new{id="sname"}) //Error at this line
<br />
<br />
Date Picker:<input type="text" id="datepicker2" /><br />
<input type="text" id="txtName2" /><br />
<input type="submit" value="GettingDataFromDB"/>
}
我究竟做错了什么?