feat: add Menu ContextMenu and Button examples (#21)
This commit is contained in:
Родитель
72cee83120
Коммит
a9e68b0c4e
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Telerik.Examples.RazorPages.Models
|
||||
{
|
||||
public class Category
|
||||
{
|
||||
public Category()
|
||||
{
|
||||
Products = new HashSet<Product>();
|
||||
}
|
||||
|
||||
public int CategoryID { get; set; }
|
||||
public string CategoryName { get; set; }
|
||||
public string Description { get; set; }
|
||||
public byte[] Picture { get; set; }
|
||||
|
||||
public virtual ICollection<Product> Products { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Telerik.Examples.RazorPages.Models
|
||||
{
|
||||
public class Product
|
||||
{
|
||||
public int ProductID { get; set; }
|
||||
|
||||
public int CategoryID { get; set; }
|
||||
public string ProductName { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
@page
|
||||
@model Telerik.Examples.RazorPages.Pages.Button.ButtonIndexModel
|
||||
@{
|
||||
ViewData["Title"] = "ButtonIndex";
|
||||
}
|
||||
|
||||
|
||||
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<h1>ButtonIndex</h1>
|
||||
|
||||
<form method="post">
|
||||
<input type="text" name="description">
|
||||
<br/>
|
||||
@(Html.Kendo().Button()
|
||||
.Name("primaryTextButton")
|
||||
.HtmlAttributes(new { type = "submit", @class = "k-primary" })
|
||||
.Events(e => e.Click("onClick"))
|
||||
.Content("Submit")
|
||||
)
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
function onClick() {
|
||||
return kendo.antiForgeryTokens();
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace Telerik.Examples.RazorPages.Pages.Button
|
||||
{
|
||||
public class ButtonIndexModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnPost(string description)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
@page
|
||||
@model Telerik.Examples.RazorPages.Pages.ContextMenu.ContextMenuIndexModel
|
||||
@{
|
||||
ViewData["Title"] = "ContextMenuIndex";
|
||||
}
|
||||
|
||||
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<h1>ContextMenuIndex</h1>
|
||||
|
||||
<div id="target">Right click here</div>
|
||||
|
||||
@(Html.Kendo().ContextMenu()
|
||||
.Name("RequestMenu")
|
||||
.Target("#target")
|
||||
.Orientation(ContextMenuOrientation.Vertical)
|
||||
.Items(items =>
|
||||
{
|
||||
items.Add()
|
||||
.Text("Edit");
|
||||
|
||||
items.Add()
|
||||
.Text("Cancel");
|
||||
})
|
||||
.Events(e =>
|
||||
{
|
||||
e.Select("onSelect");
|
||||
|
||||
})
|
||||
)
|
||||
|
||||
<script>
|
||||
function onSelect(e) {
|
||||
if ($(e.item).text() == "Edit") {
|
||||
$.ajax({
|
||||
url: "/ContextMenu/ContextMenuIndex?handler=Custom",
|
||||
type: "POST",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
headers: {
|
||||
RequestVerificationToken: $('input:hidden[name="__RequestVerificationToken"]').val()
|
||||
},
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
options.success(data);
|
||||
},
|
||||
failure: function (response) {
|
||||
console.log(response);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace Telerik.Examples.RazorPages.Pages.ContextMenu
|
||||
{
|
||||
public class ContextMenuIndexModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnPostCustom()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
@page
|
||||
@model Telerik.Examples.RazorPages.Pages.Menu.MenuRemoteDataModel
|
||||
@{
|
||||
ViewData["Title"] = "MenuRemoteData";
|
||||
}
|
||||
|
||||
@inject Microsoft.AspNetCore.Antiforgery.IAntiforgery Xsrf
|
||||
@Html.AntiForgeryToken()
|
||||
|
||||
<h1>MenuRemoteData</h1>
|
||||
|
||||
@(Html.Kendo().Menu()
|
||||
.Name("Menu")
|
||||
.DataTextField("Name")
|
||||
.DataSource(ds => ds
|
||||
.Read(r => r
|
||||
.Url("/Menu/MenuRemoteData?handler=Read").Data("dataFunction")
|
||||
)
|
||||
.Model(model => model.Children("Products")))
|
||||
)
|
||||
|
||||
<script>
|
||||
function dataFunction() {
|
||||
return kendo.antiForgeryTokens();
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Telerik.Examples.RazorPages.Models;
|
||||
|
||||
namespace Telerik.Examples.RazorPages.Pages.Menu
|
||||
{
|
||||
public class MenuRemoteDataModel : PageModel
|
||||
{
|
||||
public static List<Category> categories;
|
||||
public void OnGet()
|
||||
{
|
||||
if (categories == null)
|
||||
{
|
||||
categories = new List<Category>()
|
||||
{
|
||||
new Category(){
|
||||
CategoryID = 1,
|
||||
CategoryName = "Clothes",
|
||||
Products = new List<Product>()
|
||||
{
|
||||
new Product(){ ProductID = 10, ProductName = "Dresses", CategoryID = 1},
|
||||
new Product(){ ProductID = 11, ProductName = "T-shirts", CategoryID = 1}
|
||||
}
|
||||
|
||||
},
|
||||
new Category(){
|
||||
CategoryID = 2,
|
||||
CategoryName = "Furniture",
|
||||
Products = new List<Product>()
|
||||
{
|
||||
new Product(){ ProductID = 12, ProductName = "Sofas", CategoryID = 2},
|
||||
new Product(){ ProductID = 13, ProductName = "Accessories", CategoryID = 2},
|
||||
new Product(){ ProductID = 14, ProductName = "Tables", CategoryID = 2}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public JsonResult OnGetRead()
|
||||
{
|
||||
var result = categories.ToList().Select((category) =>
|
||||
new
|
||||
{
|
||||
Name = category.CategoryName,
|
||||
Products = category.Products
|
||||
.Where((product) => product.CategoryID == category.CategoryID)
|
||||
.Select((product) => new { Name = product.ProductName })
|
||||
}
|
||||
);
|
||||
return new JsonResult(result);
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче