這是我的理解是默認的模型粘合劑能夠轉動C#MVC:何時使用特定(非默認)ModelBinder?
<input type="text" name="myType.property1" value="John Doe" />
<input type="text" name="myType.property2" value="22" />
成:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SomeAction(MyType myType)
{
// This will be "John Doe"
String someName = myType.property1;
// This will be 22
Int32 someNumber = myType.property2;
//
// irrelevant magic
}
在什麼情況下我會使用非默認的模型綁定?我不能想到一個理由,不要命名HTML輸入與類屬性名稱不同。請舉例說明。
謝謝!
你可以添加一個自定義modelbinder實現的例子嗎? – Alex 2009-06-10 20:14:21
Alex,我在一個單獨的答案中添加了一個自定義的模型綁定器實現。 – 2009-06-10 20:20:53