<commit_before>---
layout: post
title: Ruminations on ASP.NET MVC and JavaScript Frameworks
category: programming
tags: 
    - knockoutjs
    - mithriljs
    - ASP.NET MVC
---

After the previous two posts (you can find part one [here]({% post_url 2016-04-25-bootstrap-modals-and-razor %}) and part two [here]({% post_url 2016-05-02-forms-in-bootstrap-modal-partial-view.md %})) I've been thinking about the best way to integrate ASP.NET MVC with client side frameworks like [knockout.js](http://knockoutjs.com/). With unobtrusive ajax and the `Ajax.BeginForm` or `Ajax.ActionLink` you can use very little JavaScript to create sites that behave nominally like a heavy client side app. Unless you are doing a single page app, are there benefits in using JavaScript frameworks?

Yes. At least I think so. [Maybe? I don't know.](https://www.youtube.com/watch?v=x5Za8HggalY)

Let's take a look at an example. Say you want to use [Select2](https://select2.github.io/) and add some more functionality to a select list. If you are already using knockout then you just include the [select2 binding](https://github.com/select2/select2/wiki/Knockout.js-Integration) and you are good to go. But if you weren't already using knockout, is this enough of a reason to start? Using select2 is simple enough, especially if you are filling the option list server-side using Razor. Just take the id of the select and there you go.

```javascript
$(document).ready(function() {
  $(".js-example-basic-single").select2();
});
```

> Example from the select 2 documentation: [https://select2.github.io/examples.html](https://select2.github.io/examples.html)

Even if you are doing something fancy, like loading the data using ajax, select2 itself will handle it for you. So if all you are doing is adding in select2, I don't think I would bother adding in knockout.
<commit_msg>fix for url link in the newest post<commit_after>---
layout: post
title: Ruminations on ASP.NET MVC and JavaScript Frameworks
category: programming
tags: 
    - knockoutjs
    - mithriljs
    - ASP.NET MVC
---

After the previous two posts (you can find part one [here]({% post_url 2016-04-25-bootstrap-modals-and-razor %}) and part two [here]({% post_url 2016-05-02-forms-in-bootstrap-modal-partial-view %})) I've been thinking about the best way to integrate ASP.NET MVC with client side frameworks like [knockout.js](http://knockoutjs.com/). With unobtrusive ajax and the `Ajax.BeginForm` or `Ajax.ActionLink` you can use very little JavaScript to create sites that behave nominally like a heavy client side app. Unless you are doing a single page app, are there benefits in using JavaScript frameworks?

Yes. At least I think so. [Maybe? I don't know.](https://www.youtube.com/watch?v=x5Za8HggalY)

Let's take a look at an example. Say you want to use [Select2](https://select2.github.io/) and add some more functionality to a select list. If you are already using knockout then you just include the [select2 binding](https://github.com/select2/select2/wiki/Knockout.js-Integration) and you are good to go. But if you weren't already using knockout, is this enough of a reason to start? Using select2 is simple enough, especially if you are filling the option list server-side using Razor. Just take the id of the select and there you go.

```javascript
$(document).ready(function() {
  $(".js-example-basic-single").select2();
});
```

> Example from the select 2 documentation: [https://select2.github.io/examples.html](https://select2.github.io/examples.html)

Even if you are doing something fancy, like loading the data using ajax, select2 itself will handle it for you. So if all you are doing is adding in select2, I don't think I would bother adding in knockout.

{'fraction_non_alphanumeric': 0.09675690163495042, 'fraction_numerical': 0.016081479496113642, 'mean_word_length': 4.248945147679325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3946594', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1031, 'n_words': 481}