Custom Html Helpers for asp.net mvc

  1. public static class CustomHelpers
  2. {
  3. //Submit Button Helper
  4. public static MvcHtmlString SubmitButton(this HtmlHelper helper, string
  5. buttonText)
  6. {
  7. string str = “<input type=\”submit\” value=\”” + buttonText + “\” />“;
  8. return new MvcHtmlString(str);
  9. }
  10. //Readonly Strongly-Typed TextBox Helper
  11. public static MvcHtmlString TextBoxFor<TModel, TValue>(this
  12. HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TValue>>
  13. expression, bool isReadonly)
  14. {
  15. MvcHtmlString html = default(MvcHtmlString);
  16.  
  17. if (isReadonly)
  18. {
  19. html = System.Web.Mvc.Html.InputExtensions.TextBoxFor(htmlHelper,
  20. expression, new { @class = “readOnly”,
  21. @readonly = “read-only” });
  22. }
  23. else
  24. {
  25. html = System.Web.Mvc.Html.InputExtensions.TextBoxFor(htmlHelper,
  26. expression);
  27. }
  28. return html;
  29. }
  30. }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s