2
我有一個textarea,我需要在某些條件下更改輸入類型。我想以ViewBag參數的形式發送這些信息,但我無法弄清楚如何去做。不過,我覺得這在控制器:如何使用ViewBag在mvc中添加Html Helper
if(inputtext == 1)
ViewBag.TextBox = @Html.TextBoxFor(m => m.Name, new { @class =\"inputtext\"})
if(inputtext == 2)
ViewBag.TextBox = @Html.TextAreaFor(m => m.Name, new { @class =\"inputtext2\"})
我的看法是這樣的:
@Html.Raw(ViewBag.TextBox)
但不起作用。任何想法如何做到這一點?在您的控制器
:在您的CSHTML
if(A){ ViewBag.NameControlType = "textbox" }
if(B){ ViewBag.NameControlType = "textarea" }
: