3

At the moment it is just an intellectual excercise for I do not have time to invest in this, but I am interested if anyone has any experience entirely replacing jQuery with another javascript framework like Dojo Toolkit or Google Closure.

How much of the jQuery is actually baked in to the MVC framework or is it all implemented in an unobtrusive manner so that at least in theory, it all can be replaced...

What would be involved in replacing entire javascript framework?

2
  • Any specific MVC framework or MVC frameworks in general? Each implementation is different that may or may not use jQuery. Commented Apr 6, 2011 at 7:25
  • I meant asp.net mvc. I fixed the title to spell it out (it was tagged for asp.net mvc, so I figured, this was enough) Commented Apr 6, 2011 at 7:29

2 Answers 2

2

There is nothing baked up into jQuery, it's all about the developer, if you want to use it, it will use jQuery, if you want to use ASP.NET Ajax Library it will use that, if you want to use anything else ... same answer.

When you have a Model with some validation, the only thing that the .NET Framework does is add data- attributes to the input form, from this you can elaborate your own version to do client validations.

For example:

[Required]
[ValidatePasswordLength]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }

[DataType(DataType.Password)]
[Display(Name = "Confirm password")]
[Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
public string ConfirmPassword { get; set; }

and then

<div class="editor-label">
    @Html.LabelFor(m => m.Password)
</div>
<div class="editor-field">
    @Html.PasswordFor(m => m.Password)
    @Html.ValidationMessageFor(m => m.Password)
</div>

<div class="editor-label">
    @Html.LabelFor(m => m.ConfirmPassword)
</div>
<div class="editor-field">
    @Html.PasswordFor(m => m.ConfirmPassword)
    @Html.ValidationMessageFor(m => m.ConfirmPassword)
</div>

will translate into

<div class="editor-label">
    <label for="Password">Password</label>
</div>
<div class="editor-field">
    <input data-val="true" data-val-length="&amp;#39;Password&amp;#39; must be at least 6 characters long." data-val-length-min="6" data-val-required="The Password field is required." id="Password" name="Password" type="password">
    <span class="field-validation-valid" data-valmsg-for="Password" data-valmsg-replace="true"></span>
</div>

<div class="editor-label">
    <label for="ConfirmPassword">Confirm password</label>
</div>
<div class="editor-field">
    <input data-val="true" data-val-equalto="The password and confirmation password do not match." data-val-equalto-other="*.Password" id="ConfirmPassword" name="ConfirmPassword" type="password">
    <span class="field-validation-valid" data-valmsg-for="ConfirmPassword" data-valmsg-replace="true"></span>
</div>

From here you can create your own Client Side validation. The code above was taken from the default project and it has no jQuery integration...

If you want jQuery integration, then all you need to do is append those 2 files:

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

as well jQuery Library off course, so as you can see, you, has in all .NET Framework, are the one that tells the Framework what to do, not the other way around ;)

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, this seems to align with my intuitive assessment as well. The only problem with adopting alternative js framework on top of asp.net mvc seems to be that most of the 3rd party libraries sem to take jquery stuff for granted, so I'd have to be careful with this...
jQuery is the best Javascript Framework out there :) You can do all and works great with other frameworks as well. Just think why Microsoft adopted jQuery and the investment that they are putting into jQuery... no other has it.
Well, that's a matter of opinion, isnt't it. I think MS adopted jQuery because it is an excellent javascript library with a vibrant community and by a huge margin the largest mindshare out there, but it is in no way the only player in the field. The Dojo Toolkit and Google's Closure I mentioned in my question are just as good and they also have their loyal following that likes their programming model and style over jQuery...
I think it all goes down to what we are comfortable with :)
1

client side validation in asp.net mvc-3 is based on html-5 attributes and if you do not include jquery validate and ouobtrusive scripts on your page it will fall back to server side validation only. this is first proof of being unobtrusive. so, i believe, in theory you can roll your own validation framework in any js library you want. your own validation framework must also be using these html-attributes for validation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.