ASP.NET AJAX Controls in MVC3?

2019-07-19 16:09发布

问题:

How would I use the ASP.NET AJAX Controls in MVC3?

e.g. Masked Edit Box

I've installed AJAX Control via NUGET.

and tried adding Register TagPrefix="asp" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" to the top of the page. but it is not recognised.

And I wonder if its even possible in MVC3 since Ive Never used the toolbar. It would make life so much easier If I could use these tools.

回答1:

Any ASP.NET server control is meant to be used in Webforms, not in MVC.

You'll have to find some other HTML helper method to do that or create one yourself so that you may call it like this in your page:

@this.Html.MaskedEditorBoxFor(m => m.WhateverProperty)


回答2:

Those controls are designed for the aspx rendering engine. If you are using the Razor engine, you need to look up other alternatives for the masked edit box, like some jQuery plugin.

I found this: http://digitalbush.com/projects/masked-input-plugin/

Haven't used it, so I cannot vouch for it...