You can create a HtmlHelper like:
public static class Helpers {
public static MvcHtmlString Button(this HtmlHelper html, string id, string url) {
var builder = new TagBuilder("a");
builder.MergeAttribute("href", url);
builder.MergeAttribute("id", id);
builder.AddCssClass("custom-button");
return MvcHtmlString.Create(builder.ToString(TagRenderMode.Normal));
}
}
In the view:
@Html.Button("CustomButton", "http://localhost")
The JS using JQuery:
$(function() {
$(".custom-button").click(function() {
// This will handle all the click events of the buttons
});
$("#CustomButton").click(function() {
// This will handle the click event on the specific button
});
});
As Darin said, there are no more user controls as we had in asp.net webforms, and according to me that's a very good thing.
So the code above is a way to build a "user control".