public static string Build(string name = "", int?value = null, bool isRequired = false) { var markup = $@" <input type='text' style='position: absolute; pointer-events: none; z-index: -1; opacity: 0;' tabindex='-1' name='{name}' value='{value}' id='RegateUser_{name}' {(isRequired ? " required='required' " : "")} /> <a class='btn btn-info' href='/User/SelectUser/?field={name}' onclick='return PopupCenter(this.href, ""ExirUserSelect"", 600, 700)'>انتخاب</a> <span id='RegateUser_{name}_Name'> {RemarkUserId.Build(value)} </span> "; var initScript = @" <script> function initRegateUser(name) { window['__setUser_' + name] = function(person) { document.getElementById('RegateUser_' + name).value = person.Id; document.getElementById('RegateUser_' + name + '_Name').innerText = person.FullName; } } </script> "; var script = $@" <script> initRegateUser('{name}'); </script> "; return(markup + initScript + script); }
public static string Build(string name = "", string value = "[]", int?provinceId = null) { if (value == null) { value = "[]"; } var ids = JArray.FromObject(JsonConvert.DeserializeObject(value)); var defaultListNames = ""; if (ids != null && ids.Count > 0) { defaultListNames += "<ul class='line-height-25 margin-top-6'>"; foreach (string id in ids) { defaultListNames += $@"<li>{RemarkUserId.Build(int.Parse(id))}</li>"; } defaultListNames += "</ul>"; } var markup = $@" <div> <a class='btn btn-info' data-role=""json"" href='/InterviewModule/SelectUserMulti/{provinceId}' onclick='return PopupCenter(this.href, ""ExirUserMultiSelect"", 900, 700)'>انتخاب</a> </div> <input type='hidden' name='{name}' value='{value}' id='RegateUserMulti_{name}' /> <div id='RegateUserMulti_{name}_List'>{defaultListNames}</div> "; var initScript = @" <script> function initRegateUserMulti(name) { window['__setUserMulti_' + name] = function(users) { console.log(users); var $list = $('#RegateUserMulti_' + name + '_List'); var $input = $('#RegateUserMulti_' + name); if (users.length === 0) { $input.val('[]'); $list.html(''); return true; } var $ul = $('<ul></ul>'); var ids = []; $.each(users, function(index, user) { $('<li></li>').text(user.FullName).appendTo($ul); ids.push(user.Id + ''); }); $list.html(''); $ul.appendTo($list); $input.val(JSON.stringify(ids)); $.fn.matchHeight._update(); } } </script> "; var script = $@" <script> initRegateUserMulti('{name}'); </script> "; return(markup + initScript + script); }