我需要在基础方面得到一些帮助...
我有一个控制器,用一个类的实例为我的视图提供服务(至少我是这么认为的)。所以,既然我正在为我的视图提供一个新的对象实例,为什么它还需要为我的后台模型绑定创建一个更加新的实例呢?请看下面的例子。
[HttpGet]
public ActionResult Index(){
int hi = 5;
string temp = "yo";
MyModel foo = new MyModel(hi, temp);
return View(foo);
}
[HttpPost]
public ActionResult Index(MyModel foo){
MyModel poo = foo;
if(poo.someString == laaaa)
return RedirctToAction("End", "EndCntrl", poo);
else
throw new Exception();
}
View:
@model myApp.models.MyModel
@html.EditorFor(m => m.hi)
<input type="submit" value="hit"/>
Model:
public class MyModel {
public int hi {get; set;}
public string someString {get; set;}
public stuff(int number, string laaaa){
NumberforClass = number;
someString = laaaa;
}
}
为什么我需要一个空白构造函数?此外,如果我有一个无参数的构造函数,为什么在到达RedirctToAction("End", "EndCntrl", poo)
之前,poo.someString
会发生变化?
class stuff != class MyModel
,hi != NumberforClass
。 - H H