C# web 总结

(1)Cshtml 中 “@” 符号转义

  在 cshtml 中需要使用 “@” 符号,如 “@幸福摩天轮版权所有”。那么我们需要使用转义,使用 “@@” 就好!“© ”和 “@” 好像呀。

<title>App下载 @@幸福摩天轮</title>

 (2)ViewDate 和 ViewBag 区别

  ViewData是字典类型,赋值方式用字典方式,通过key值读取对应的value,ViewData[“Name”]

  ViewBag是动态类型,使用时直接添加属性赋值即可ViewBag.Name

  个人建议使用 ViewBag 、简单、简洁、如类一般的方便。

(3)连接 onclick 使用

  onclick 的使用,可以取代 a 标签。

(4)jquery 调用 input 的输入时间

$("#upload").trigger('click');

 (5)设置 table 的边框

  考虑原生的太丑了,所以我们要自己写边框。设置 table 和 td 就好。

  #grzx-grxx-content-Report table td {
      border-left: 1px solid #f0f0f0;
      border-bottom: 1px solid #f0f0f0;
  }

#grzx-grxx-content-Report,#grzx-grxx-content-bindwork{
    margin:20px 75px;
    825px;
}

(6)form submit 事件

  在使用表单的 submit 事件时,button 的 type=“ submit ”。否则无效,提交后表单不需要提交事件,我们需要 return=“false” 一下。

//HTML
<button type="submit">提 交</button>

//JS
//submit提交事件
    $("#cooperationForm").submit(function (e) {

        return false;
    });

(7)Jquery 遍历

  Jquery 的 each 遍历,自己牢记!

$.each(array,function(index,value){
   $.each(value.array,function(){

    }) 
})

//这个是可以循环套的。
var area = appData.area;
    $.each(area, function (index, value) {
        $("#areaId").append('<option value="' + value.id + '">' + value.name + '</option>');
        $.each(value.children, function (index, val) {
            $("#areaId").append('<option value="' + val.id + '">&nbsp;&nbsp;&nbsp;&nbsp;' + val.name + '</option>');
        });
    });

(8)Jquery 验证简单判断

if (!$("form").valid()) {
            return;
        }

(9) return view

return View("~/Views/Home/Recruitment.cshtml",model);

 (10)Request命名空间

  using System.Web;

public static string PageUrl(this UrlHelper helper, int page, string action = null, string controller = null)
        {
            var param = new System.Web.Routing.RouteValueDictionary();
            foreach (string key in HttpContext.Current.Request.QueryString.Keys)
            {
                param.Add(key, HttpContext.Current.Request.QueryString[key]);
            }
            param["page"] = page;
            return helper.Action(action, controller, param);
        }

 (11)重定向

public ActionResult CancelFav(EntityDto<long> input)
        {
            _jobAppService.CancelFav(input);
            return RedirectToRoute(new { controller = "Job", action = "detail",id=input.Id});
        }

 这用在浏览器中的参数:http://localhost:6234/Job/Detail/16   把?id=16 换为 /16

上面这种,是通过路由的方式去请求 controller ,使用在浏览器的路由那个地方,我自己感觉不舒服。所欲我使用下面一种。

Redirect("Detail?id="+input.Id);

  这是我习惯点,这个是去访问 controller。这种的url和一样。

 (12)使用UEditor 带有html 表情还原

  使用@Html.raw() 即可  ,这个的就是输出带有 html 的标签,省略 html 元素。

 (13) 表单序列化

//submit提交事件
    $("form").submit(function (e) {
        if (!$("form").valid()) {
            return;
        }
        var data = $(this).serializeObject();
        var id = $("#id").val();
        
        if (id === null||id === "") url = "11";
        else url = "11111";

        abp.ui.setBusy(
            null,
            abp.ajax({
                contentType: app.consts.contentTypes.formUrlencoded,
                url: url,
                data: data
            }).done(function (data) {
                $("form")[0].reset();
                swal("信息提交成功!", "", "success")
            })
        );

        return false;
    });

 (14)Jquery 表单重置

  jquery的表单提交使用的是 $("#formid").submit(),那么在提交的时候想用 $('#formid').reset()   是不行我的,我们需要使用 $('#formid')[0].reset()

(15)jquery 操作textarea

$(".replay").click(function () {
        var id = $(this).attr("data-id");
        var name = "@" + $(this).attr("data-name")+"  ";
        $("textarea").val(name);
        $("input[name='replayComentId']").val(id);
        $("textarea").focus();
    });

(16) JQuery 子元素、父元素

 $("#id").parent();         // 父节点
    $("#id").parents();     // 全部父节点
    $("#id").parents(".class");
    $("#id").children();     // 全部子节点
    $("#id").children("#id1");
    $("#id").contents();     // 返回#test里面的所有内容,包括节点和文本
    $("#id").contents("#test1");
    $("#id").prev();      // 上一个兄弟节点
    $("#id").prevAll();     // 之前所有兄弟节点
    $("#id").next();     // 下一个兄弟节点
    $("#id").nextAll();     // 之后所有兄弟节点
    $("#id").siblings();     // 所有兄弟节点
    $("#id").siblings("#id1");
    $("#id").find("#id1");    

 (17)获取泛型类型名称

typeof(T).Name == "RestaurantRecruitment"
原文地址:https://www.cnblogs.com/gzbit-zxx/p/9854610.html