2011-06-26 32 views
2

使用Razor視圖引擎,我有這樣一些代碼如下:ASP.NET MVC 3文本區域默認內容

@Html.TextAreaFor(model => model.Field, 20, 100, null) 

我怎樣才能讓這個文本區域有一個默認值,即什麼是正常的<textarea></textarea>之間?

回答

3

如果您只使用默認文本填充模型上的Field屬性,它應該可以工作。它會在生成標記時自動插入文本。

如果你看一個編輯視圖,你會發現它是如何工作的。

0

做到這一點,正確的方法是從控制器內填充的模型,並將其發送給視圖。

// create a new model object 
MyViewModel model = new MyViewModel(); 

// populate the "Field" property in said object 
model.Field = "this is my field text"; 

// send the pre-populated model to the veiw 
return View(model);