Created
July 27, 2011 18:37
-
-
Save bsatrom/1110056 to your computer and use it in GitHub Desktop.
KnockoutJS and ASP.NET MVC strongly-typed helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<fieldset> | |
<legend>Speaker Info</legend> | |
Name: <input type="text" data-bind="value: name" /> <br /> | |
Bio: <textarea data-bind="value: bio"></textarea> <br /> | |
Twitter Handle: <input type="text" data-bind="value: twitterHandle" /> <br /> | |
State: <input type="text" data-bind="value: state" /> <br /> | |
</fieldset> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<fieldset> | |
<legend>Speaker Info</legend> | |
Name: @Html.TextBoxFor(m => m.Name, new { data_bind= "value: name" }) <br /> | |
Bio: @Html.TextAreaFor(m => m.Bio, new { data_bind= "value:bio" }) <br /> | |
Twitter Handle: @Html.TextBoxFor(m => m.TwitterHandle, new { data_bind= "value: twitterHandle" }) <br /> | |
State: @Html.TextBoxFor(m => m.State, new { data_bind= "value: state" }) <br /> | |
</fieldset> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modelBinder.createBindings = function (bindlist) { | |
function setBinding(id, value) { | |
var el = getElement(id); | |
if (el) { | |
el.setAttribute('data-bind', value); | |
} | |
} | |
function getElement(id) { | |
var el = document.getElementById(id); | |
if (!el) { | |
id = id.charAt(0).toUpperCase() + id.slice(1); | |
el = document.getElementById(id); | |
} | |
return el; | |
} | |
/* other code here */ | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<fieldset> | |
<legend>Speaker Info</legend> | |
Name: @Html.TextBoxFor(m => m.Name) <br /> | |
Bio: @Html.TextAreaFor(m => m.Bio) <br /> | |
Twitter Handle: @Html.TextBoxFor(m => m.TwitterHandle) <br /> | |
State: @Html.TextBoxFor(m => m.State) <br /> | |
</fieldset> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment