Any advice for use with Knockout?

Posted in General by Mel Grubb Mon Jan 11 2016 14:28:02 GMT+0000 (Coordinated Universal Time)·1·Viewed 906 times

I'm on a project now that uses Knockout on the front-end, but I'm hopelessly addicted to SpecsFor.Mvc. I imagine that if the on-page controls follow the same naming convention as MVC would have, then SpecsFor would still be able to find them and use them. As I understand it from the MvcTemplates package, the magic is in wrapping a span around the controls and naming it after the property on the viewmodel. Is this correct? Are there any examples of workable patterns for integrating with Knockout? How about other front-end technologies like Angular?
Jan 11, 2016

I have used it with Angular-enabled projects in the past, but I don't have any public samples. You are correct though: as long as your client-side elements follow the same ID convention that the server-side, generated elements would have used, things will work fine.

SpecsFor.Mvc also allows you to define your own conventions, in case the default ones won't work for you. There's an IElementConventions interface, and a virtual-member laden DefaultElementConventions class, that you can use to customize the selectors it uses to find things given a strongly-typed model.

I hope that helps!

Markdown is allowed