C # (Fill Modal Bootstrap with Ajax function)

0
public IActionResult GetAssetsTree(AssetDataModel Parent_ID, AuditIdRow row,string workspaceId){
     _assetService.CollectionName = workspaceId;
     _assetService.ParentId = workspaceId;
     return(Json(CreateTree(null,null)));
}

CreateTree calls me to a private method

private AuditIdRow CreateTree(AssetDataModel Parent, AuditIdRow row){
return row;
}

AuditIdRow Class

 public class AuditIdRow : BaseModel
    {
        public string Name {get;set;}
        public bool IsGroup{get;set;}
        public List<AuditIdRow> Children { get; set; }
    }

Vista html:

<div class="modal fade" id="modal-container-root" tabindex="1" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4>Selecciona tu código de acción para trabajar</h4>
            </div>
            <div class="modal-body">
                <div class="list-group" id="TreeGroups" role="tablist">
                    //Aqui es donde quiero cargar los datos
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>

Javascript function to load the modal:

<script>
    $(document).ready(function () {                
        $.get("GetAssetsTree") // llamo al método para que me devuelva los datos 
        .done(function (data){
            $.each(data,function(index,obj){
                $("#TreeGroups").append('<option value="'+obj.Name+'">'+obj.row.+'</option>');
            });
        })
        .fail(function(data){
            alert(data);
        } )
    });   
</script>

I want to fill in the modal with the data that comes from the getAssetTree method, where I want to show the name of AuditIdRow first, and inside it to show me the list of children to make a TreeView view within the modal.

    
asked by Sam.Gold 05.03.2018 в 14:02
source

1 answer

0

And what is the ruling you have? Do you get the data from Ajax? if so, I see that you use a foreach that initially nests the data well to the TreeGroups div, what I do not understand is because you hit them as an option if it is not a select.

    
answered by 05.03.2018 в 22:06