Skip to content

Instantly share code, notes, and snippets.

@demofan
demofan / DefaultPageRouteModelConvention.cs
Created June 22, 2019 18:10
Change RazorPage default page
public class DefaultPageRouteModelConvention : IPageRouteModelConvention
{
public void Apply(PageRouteModel model)
{
if (model.RelativePath == "/Pages/Index.cshtml")
{
var currentHomePage = model.Selectors.Single(s => s.AttributeRouteModel.Template == string.Empty);
model.Selectors.Remove(currentHomePage);
}
[HtmlTargetElement("bold",Attributes = "bold")]
public class BoldTagHelper : TagHelper
{
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.Attributes.RemoveAll("bold");
output.PreContent.SetHtmlContent("<strong>");
output.PostContent.SetHtmlContent("</strong>");
}
}
@demofan
demofan / BooleanClient.cshtml
Created December 5, 2017 05:47
陽春型 CheckBox EditorTemplates
@{
bool isChecked = false;
if (string.IsNullOrWhiteSpace(ViewData.TemplateInfo.FormattedModelValue.ToString())==false)
{
isChecked = !string.IsNullOrWhiteSpace(ViewData.TemplateInfo.FormattedModelValue.ToString()) && Convert.ToBoolean(ViewData.TemplateInfo.FormattedModelValue);
}
var dic = new Dictionary<string, string> { };
var attributes = ViewData.MergeAttributes(dic);
}
@demofan
demofan / js.js
Created August 19, 2017 10:00
Unobtrusive sample
@Html.Hidden("ajaxUrl",Url.Action(""))
<button type="button" data-ajax-url="@Url.Action("")"></button>
<script>
$(function () {
$(":input[data-ajax-url]").click(function (e) {
e.preventDefault();
var current = $(this);
$.ajax({
type: "POST",
url: current.data("url"),
@demofan
demofan / yield return.cs
Created August 14, 2016 11:30
yield return 示範
void Main()
{
var testSource = LookUp();
testSource.Dump();
}
IEnumerable<DepositModels> LookUp()
{
for (int i = 0; i < 3; i++)
{
@demofan
demofan / Order.cs
Last active January 8, 2016 10:02 — forked from dinowang/Order.cs
ASP.NET MVC QueryOption<T> implementation. depend on PagedList, PagedList.Mvc.
public enum Order
{
Ascending,
Descending
}
internal static string GetNoLastNumber(int? random = null)
{
var dictionary = new[] { "a", "b", "c", "d", "e", "f", "g", "h", "k", "m", "p", "r" };
if (random.HasValue==false)
{
random = new Random().Next(0, 9);
}
return dictionary[random.Value];
}
@demofan
demofan / MVP2016.cs
Last active October 20, 2015 09:56
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NSubstitute;
using NSubstitute.Exceptions;
namespace MVP2016
{
[TestClass]
gulp.task("前端:darkCSS", function () {
gulp.src(
[
paths.cssSource + "theme-dark.css"
])
.pipe(concat(paths.assets + "css/theme-dark.css"))
.pipe(minifycss())
.pipe(gulp.dest("."))
.pipe(notify({ message: "前端:darkCSS" }));
});
var jsonstring="[{中文="A"},{中文="B"}]"
class JsonForSearch
{
[JsonProperty("中文")]
public string pname { get; set; }
}
反序列化要吃的到
再次序列化的值希望是