@manhnguyenv

Welcome to my blog!

MVC jQuery

May 4, 2019 22:57

MVC jQuery (edit)

https://www.pluralsight.com/guides/asp-net-mvc-using-javascript-with-ajax-and-razor-partial-views

https://www.completecsharptutorial.com/asp-net-mvc5/asp-net-mvc-5-renderbody-renderpage-and-rendersection-with-example.php

https://www.c-sharpcorner.com/article/include-jquery-library-in-a-view-or-page-in-different-ways/

https://learn.jquery.com/events/event-delegation/

.NET Core

https://stormpath.com/blog/routing-in-asp-net-core

URL & Routing in MVC

http://www.dotnetinfo.org/url-routing-asp-net-mvc/

https://www.codeproject.com/Articles/1252421/Controllers-And-Routing-In-ASP-NET-MVC

Display Full URL in MVC

https://www.c-sharpcorner.com/UploadFile/17e8f6/customcontrollerfactory-in-mvc4/

https://dzone.com/articles/custom-controller-factory

https://www.codeproject.com/Articles/560798/ASP-NET-MVC-Controller-Dependency-Injection-for-Be

string actionName = this.ControllerContext.RouteData.Values["action"].ToString();
string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();

Attribute Routing

https://exceptionnotfound.net/attribute-routing-vs-convention-routing/

https://devblogs.microsoft.com/aspnet/attribute-routing-in-asp-net-mvc-5/

https://www.tutorialsteacher.com/mvc/routing-in-mvc

https://weblogs.asp.net/scottgu/asp-net-mvc-preview-5-and-form-posting-scenarios

https://www.itprotoday.com/web-application-management/techniques-personalize-your-urls-using-aspnet-mvc (Include the {Day}/{Month}/{Year} in the URL)

Đăng ký sự kiện trong MVC View Razor

@section scripts
{
<script>
$(document).ready(function() {
alert("Hey! I am ready.");
});
</script>
}

Đăng ký sự kiện click

<body>
<div id="container">
<ul id="list">
<li><a href="http://domain1.com">Item #1</a></li>
<li><a href="/local/path/1">Item #2</a></li>
<li><a href="/local/path/2">Item #3</a></li>
<li><a href="http://domain4.com">Item #4</a></li>
</ul>
</div>
</body>
// Attach a directly bound event handler
$( "#list a" ).on( "click", function( event ) {
  event.preventDefault();
  console.log( $( this ).text() );
});
// Add a new element on to our existing list
$( "#list" ).append( "<li><a href='http://newdomain.com'>Item #5</a></li>" );
// Attach a delegated event handler
$( "#list" ).on( "click", "a", function( event ) {
  event.preventDefault();
  console.log( $( this ).text() );
});
// Attach a delegated event handler
$( "#list" ).on( "click", "a", function( event ) {
  var elem = $( this );
  if ( elem.is( "[href^='http']" ) ) {
    elem.attr( "target", "_blank" );
  }
});

Đăng ký sự kiện click

<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(document).ready(function () {
$('#btn').click(function (e) {
$("p").hide();
e.preventDefault();
});
});
</script>
</head>

Đăng ký sự kiện click

Is your button being dynamically rendered through AJAX after the initial page load?

Use

$(document).on("click", ".btn", function(){

instead of

$(".btn").click(function(){

Đăng ký sự kiện click

You need to use the event delegation syntax of .on() here. Change:

$("#myBtn").click(function() {

to

$("#myForm").on('click', '#myBtn', function () {

Categories

Recent posts