Throughout my app, I'd like to use Razor for all functionality related to Reading, and leverage knockoutJS and AJAX for CUD operations.
In my profile view, I've done the following:
<div>
<h4>About Me</h4>
<!-- ko if: !isEditingAboutMe() -->
<p>@Model.User.AboutMe</p>
@if (Model.CurrentUserCanEdit)
{
<a data-bind="click: editAboutMe">edit</a>
}
<!-- /ko -->
<!-- ko if: isEditingAboutMe() -->
@Html.TextBoxFor(model => model.User.AboutMe, new { data_bind = "value: aboutMe" })
<a data-bind="click: saveAboutMe">save</a>
<a data-bind="click: cancelAboutMe">cancel</a>
<!-- /ko -->
</div>
This way search engines can at least crawl the content, and users with javascript enabled can perform CUD operations. The idea is that users with javascript disabled and search engines will get a usable read-only version of the app with no edit capabilities shown.
My problem above is that - search engines will see the editing controls since they're wrapped in ko statements. What's the best way to prevent this from happening?
One solution I can think of is adding display: none
to each of the edit controls and re-enabling it with knockout attribute bindings... thoughts?
Also - feedback regarding the "properness" of this approach is welcome.