How to get HtmlAttributes in custom EditTemplate
in MVC5
Dienstag, 17. März 2015
Assume you habe a view using Html.EditorFor like this:
@Html.EditorFor(model => model, new { htmlAttributes = new { @data_test = "value" } })
and have a EditTemplate which needs to add the attributes:
@model int?
@{
var htmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(ViewData["htmlAttributes"]);
htmlAttributes.Add("class", "myclass");
}
<div class="justsomething">
@Html.Hidden("", Model, htmlAttributes)
</div>
Which results in
<div class="justsomething">
<input type="hidden" data-test="value" value=""/>
</div>
Blog / Lothar Steidle
Letzte Einträge
Montag, 9. Januar 2023
Cool uses for css Variables
Freitag, 21. August 2020
Dynamische Hintergrundbilder ohne Inline Styles verwenden
ohne csp unsafe-inline
Dienstag, 1. Oktober 2019
Content-Security-Policy
Sichere Websites
Montag, 2. April 2018
Piwik/Matomo Opt Out Iframe funktioniert nicht
In einer Multidomain Installation
Freitag, 23. März 2018
Website mit Bootstrap druckt keine Hintergrundfarben
Alle anzeigen (10)
Beliebteste Einträge
Donnerstag, 4. Februar 2016
Intellisense not working for Razor Views
Montag, 7. Juli 2014
Send a Posted Form through Modelbinder as Email
In C# MVC
Mittwoch, 30. März 2016
Essential Visual Studio 2015 Extensions
for Webdevelopers
Montag, 6. Oktober 2014
How to use a font-awesome icon for submenu
...and animate it
Montag, 2. April 2018
Piwik/Matomo Opt Out Iframe funktioniert nicht
In einer Multidomain Installation
Alle anzeigen (10)