asp.net.mvc Editor cascading

asp.net.mvc Editor cascading

hjsmwzhjsmwz Posts: 4Questions: 1Answers: 0

我需要一个详细的例子:包括Controller、javascript、Database及Model的设计,这个问题把我搞晕了。谢谢!

Answers

  • hjsmwzhjsmwz Posts: 4Questions: 1Answers: 0

    我的Controller:
    [System.Web.Mvc.AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
    public ActionResult Table()

        {
    
            var settings = Properties.Settings.Default;
    
            var formData = HttpContext.Request.Form;
            using (var db = new Database(settings.DbType, settings.DbConnection))
            {
    
    
                var response = new Editor(db, "xiangmubiaos")
                    .Model<LuruModel>()
                     .Field(new Field("xiangmubiaos.Gcmc")
                        .Validator(Validation.NotEmpty())
                    )
                    .Field(new Field("xiangmubiaos.Sjdw")
                        .Options(new Options()
                          .Table("Sjdws")
                         .Value("id")
                         .Label("name")
                       )
                       .Validator(Validation.DbValues(new ValidationOpts { Empty = false }))
                   )
                   .Field(new Field("xiangmubiaos.Qtks")
                        .Options(new Options()
                          .Table("Qtkss")
                         .Value("id")
                         .Label("name")
                       )
                        .Validator(Validation.DbValues(new ValidationOpts { Empty = false }))
                   )
                    .Field(new Field("xiangmubiaos.QtksFzr")
                        .Options(new Options()
                          .Table("QtksFzrs")
                         .Value("id")
                         .Label("name")
                       )
                        .Validator(Validation.DbValues(new ValidationOpts { Empty = false }))
                   )
                    .Field(new Field("xiangmubiaos.Sgdw")
                        .Options(new Options()
                          .Table("Sgdws")
                         .Value("id")
                         .Label("name")
                       )
                        .Validator(Validation.DbValues(new ValidationOpts { Empty = false }))
                   )
                    .Field(new Field("xiangmubiaos.Dqsj")
    
                    .Validator(Validation.DateFormat(
    
                        Format.DATE_ISO_8601,
    
                        new ValidationOpts { Message = "Please enter a date in the format yyyy-mm-dd" }
    
                    ))
    
                    .GetFormatter(Format.DateSqlToFormat(Format.DATE_ISO_8601))
    
                    .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_8601))
    
                )
    
                    .LeftJoin("Sjdws", "Sjdws.id", "=", "xiangmubiaos.Sjdw")
                    .LeftJoin("Qtkss", "Qtkss.id", "=", "xiangmubiaos.Qtks")
                    .LeftJoin("QtksFzrs", "QtksFzrs.Qtks", "=", "xiangmubiaos.QtksFzr")
    
                    .LeftJoin("Sgdws", "Sgdws.id", "=", "xiangmubiaos.Sgdw")
    
    
                   .Process(formData)
                    .Data();
    
                return Json(response, JsonRequestBehavior.AllowGet);
            }
        }
    
  • hjsmwzhjsmwz Posts: 4Questions: 1Answers: 0

    var editor;

    $(document).ready(function() {

    editor = new $.fn.dataTable.Editor( {
    
        ajax:"/Lurus/Table",
    
        table: "#example",
        fields: [{
                label: "工程名称:",
                name: "xiangmubiaos.Gcmc"
            }, {
                label: "三级单位:",
                name: "xiangmubiaos.Sjdw",
                  type: "select"
            }, {
                label: "牵头科室:",
                name: "xiangmubiaos.Qtks",
                type: "select",
    
            }, {
                label: "负责人:",
                name: "xiangmubiaos.QtksFzr",
                type: "select"
            }, {
                label: "施工单位:",
                name: "xiangmubiaos.Sgdw",
                type: "select"
            },{
                label: "时间:",
                name: "xiangmubiaos.Dqsj",
                type: "datetime",
                def: function () { return new Date(); }
            }
        ]
    });
    
    // Activate an inline edit on click of a table cell
    $('#example').on('click', 'tbody td:not(:first-child)', function (e) {
        editor.inline(this, {
            onBlur: 'submit'
      });
    });
    

    // editor.dependent('xiangmubiaos.Qtks', '/api/qtfzrs');

    $('#example').DataTable( {
    
        dom: 'Bfrtip',
        ajax: {
            url: "/Lurus/Table",
            type: 'POST'
        },
        order: [1, 'asc'],
        columns: [{
            data: null,
            defaultContent: '',
            className: 'select-checkbox',
            orderable: false
           },
    
            { data: "xiangmubiaos.Gcmc" },
    
            { data: "Sjdws.name" , editField: "xiangmubiaos.Sjdw"},
    
            { data: "Qtkss.name", editField: "xiangmubiaos.Qtks" },
            { data: "QtksFzrs.name", editField: "xiangmubiaos.QtksFzr" },
            { data: "Sgdws.name", editField: "xiangmubiaos.Sgdw"},
            { data: "xiangmubiaos.Dqsj", editField: "xiangmubiaos.Dqsj" }
    
        ],
    
       // select: true,
    
        select: {
            style: 'os',
            selector: 'td:first-child'
        },
    
        buttons: [
            { extend: 'create', editor: editor },
            { extend: 'edit',   editor: editor },
            { extend: 'remove', editor: editor }
        ]
    
    
    } );
    

    } );

  • hjsmwzhjsmwz Posts: 4Questions: 1Answers: 0

This discussion has been closed.