1. Multiple Button on Razor page or Multiple Button on form tag with different action
a. cshtml page
@page
@model WebApplicationRazor.Pages.Customer2.index2Model
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>index2</title>
</head>
<body>
Rinkesh<br>
@ViewData["msg"]
<br>
<form method="post">
<div>Slill you know </div>
<input type="submit" value="Jave" asp-page-handler="JavaSkill" asp-route-sessioncount="30" />
<br>
<input type="submit" value="PHP" asp-page-handler="PhpSkill" asp-route-sessioncount="20" />
<br>
<input type="submit" value="CPP" asp-page-handler="CPPSkill" asp-route-sessioncount="5" />
</form>
</body>
</html>
b. cshtml.cs page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApplicationRazor.Pages.Customer2
{
public class index2Model : PageModel
{
public void OnGet()
{
}
public void OnPostJavaSkill(int sessionCount)
{
ViewData["msg"] = $"Your query for { sessionCount } is processed.";
}
public void OnPostPHPSkill(int sessionCount)
{
ViewData["msg"] = $"Your query for { sessionCount } is processed.";
}
public void OnPostCPPSkill(int sessionCount)
{
ViewData["msg"] = $"Your query for { sessionCount } is processed.";
}
}
}
a. cshtml page
@page
@model WebApplicationRazor.Pages.Customer2.index2Model
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>index2</title>
</head>
<body>
Rinkesh<br>
@ViewData["msg"]
<br>
<form method="post">
<div>Slill you know </div>
<input type="submit" value="Jave" asp-page-handler="JavaSkill" asp-route-sessioncount="30" />
<br>
<input type="submit" value="PHP" asp-page-handler="PhpSkill" asp-route-sessioncount="20" />
<br>
<input type="submit" value="CPP" asp-page-handler="CPPSkill" asp-route-sessioncount="5" />
</form>
</body>
</html>
b. cshtml.cs page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace WebApplicationRazor.Pages.Customer2
{
public class index2Model : PageModel
{
public void OnGet()
{
}
public void OnPostJavaSkill(int sessionCount)
{
ViewData["msg"] = $"Your query for { sessionCount } is processed.";
}
public void OnPostPHPSkill(int sessionCount)
{
ViewData["msg"] = $"Your query for { sessionCount } is processed.";
}
public void OnPostCPPSkill(int sessionCount)
{
ViewData["msg"] = $"Your query for { sessionCount } is processed.";
}
}
}
No comments:
Post a Comment