我面临与AngularJS数据绑定的问题

时间:2017-01-02 10:59:17

标签: jquery asp.net angularjs asp.net-mvc jquery-ui-datepicker

我是Angular JS的新手。我面临与AngularJS数据绑定的问题。它适用于字符串,但它不适用于日期时间。我正在使用带有Angular JS的ASP.net MVC和用于Date Picker的jQuery UI。

  1. 数据来自JSON格式的数据库(控制器)。
  2. 通过使用Angular JS进行数据绑定,它会自动设置为输入框。
  3. 在输入框中附加了jQuery UI日期选择器。
  4. 它适用于除datetime之外的所有字段。

    案例1:如果我设置输入类型=“日期”     然后输入日期字段为空。

    案例2:如果我设置输入类型=“字符串”     然后它显示输入的值即。 /日期(14814.81亿)/

    这是我的控制器代码:

        // GET: ProductMaster/Details/5
        public ActionResult Details(int PrimaryKey)
        {
            try
            {
                using (LOAN_APPRAISAL_TESTEntities db = new LOAN_APPRAISAL_TESTEntities())
                {
    
                    var v = (from v1 in db.m_ProductMaster where v1.ProductID == PrimaryKey select v1).First();
                    ProductMasterModel product = new ProductMasterModel();
                    v.MapToModelObject(product);
                    return Json(product, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception e1)
            {
                return Json(new ResultModel() { Result = tssiplResultType.tssiplError, Message = e1.Message, Data = null }, JsonRequestBehavior.AllowGet);
            }
        }
    

    这是我的Angular JS代码

    $.ajax({
            url: '/ProductMaster/Details',
            type: 'GET',
            cache: false,
            async: false,
            data: { PrimaryKey: ProductID },
            contentType: 'application/json; charset=utf-8',
            error: function (a, b, c) {
                HideBusy();
                alert(a.responseText);
            },
            success: function (a, b, c) {
                HideBusy();
                debugger;
                $scope.ProductMasterModel = a; // this is my Angular Model
    
                //debugger;
                  //debugger;
                $('#divEdit').modal('show');
            }
        });
    

    这是我的HTML

                            <div class='input-group date .form_datetime'>
                                <label>Valid From</label>
                                <input class="form-control" ControlType="Date" type="date" 
                                       min="1900-01-01"
                                       max="2500-01-01"
                                       ng-model="ProductMasterModel.ValidFrom" />
    
                            </div>
    
    
                            <label>Valid To</label>
                            <input class="form-control" ControlType="Date" type="text" 
                                       min="1900-01-01"
                                       max="2500-01-01"
                                       ng-model="ProductMasterModel.ValidTo"/>
    
      

    注意:   我不想使用input type =“date”,因为HTML5日期选择器不适用于所有浏览器,因此更喜欢使用jQuery UI datepicker。

    我已经浏览了几个链接,每个链接都显示格式化日期并以跨度显示。

1 个答案:

答案 0 :(得分:0)

在您的字段中使用角度<?php class Vasya { public $name = __CLASS__; } $class = new Vasya(); echo $class->name; // result Vasya class Petro extends Vasya { } $class = new Petro(); echo $class->name; // result Vasya // Why???

$filter