C# MVC前端引用model用法

C# MVC前端引用model用法

Mvc服务器端return view()

前端接收,view()里面是什么类型的,前端的model也是要引用同样的类型,不然会报错。

 

例子:

@using OrderSystem.APIControllers;
@model OrderSystem.framework.BaseResponse<TradeDetailsResponse>

@{
    ViewBag.Title = "BankCardTest";
    //Layout = "~/Views/Shop/_layoutTop.cshtml";
}

<h2>BankCardTest</h2>

@using OrderSystem.Enum

@{
    ViewBag.Title = "UsersTradeDetails";
    Layout = "~/Views/Shop/_layoutTop.cshtml";
}
<div class="Floor mgt15 w1280 u-content">
    @Html.Partial("PartialUserLeft")


    <div class="u-right">
        @{
            if (Model != null)
            {
                <!-- 我的订单 -->
                <div class="box_1">
                    <div class="m-box">
                        <h5><span>订单状态</span></h5>
                        <div class="m-Cont">

                            @{
                                if (Model != null)
                                {
                                    if (Model.Result.Status != TradeStatusEnum.TRADE_CLOSED.ToString() && Model.Result.Status != TradeStatusEnum.TRADE_CLOSED_BY_USER.ToString())
                                    {
                                        <div id="sflex04" class="stepflex ">

                                            @if (Model.Result.ConfirmDate != null)
                                            {
                                                <dl class="first curr">
                                                    <dt class="s-num">1</dt>
                                                    <dd class="s-text">买家已下单<s></s><b></b></dd>
                                                    <dd>@Model.Result.ConfirmDate.ToString("yyyy-MM-dd HH:mm:ss")</dd>
                                                </dl>
                                            }

==========================================================

public class BaseResponse<T>
    {
        public BaseResponse()
        {
            Status = BaseResponseStatusEnum.Error;   //默认失败
            Msg = "查无数据";
        }
        public string Msg { get; set; }
        public BaseResponseStatusEnum Status { get; set; }
        //public string 
        public T Result { get; set; }
    }

 

/// <summary>
    /// 订单详情(包括Trade 和 Order)
    /// </summary>
    public class TradeDetailsResponse 
    {
        /// <summary>
        /// 下单用户名字
        /// </summary>
        public string UserName { get; set; }
        /// <summary>
        /// 下单用户金蝶代码
        /// </summary>
        public string Ext_UID { get; set; }
        /// <summary>
        /// 下单用户金蝶名字
        /// </summary>
        public string Erp_AllName { get; set; }
        /// <summary>
        /// 客服名字
        /// </summary>
        public string ExtName { get; set; }
        /// <summary>
        /// 客服扩展代码
        /// </summary>
        public string ExtCode { get; set; }
 }

 

posted on 2022-10-28 17:56  Jankie1122  阅读(164)  评论(0编辑  收藏  举报