Google Analytics İzleme

23 Aralık 2011

asp.net mvc 3 - Html.Textbox'a ViewBag'den değer atama

@Html.TextBox("txtProspectiveStudentsSurveyId", @ViewBag.ProspectiveStudentsSurveyId)
şeklinde yapınca aşağıdaki şekilde hata aldım:

CS1973: 'System.Web.Mvc.HtmlHelper<dynamic>' has no applicable method named 'TextBox' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

@Html.TextBox("txtProspectiveStudentsSurveyId", ViewBag.ProspectiveStudentsSurveyId) şeklinde yaptım yine aynı hatayı aldım.

Doğrusu:
@Html.TextBox("txtProspectiveStudentsSurveyId", (string)ViewBag.ProspectiveStudentsSurveyId)
şeklinde casting yapmak gerekiyormuş.

Kaynak:
http://stackoverflow.com/questions/7190682/add-html-textbox-value-from-viewbag



Hiç yorum yok: