一沙框架 前端请求后端数据的实现方法
1、前端页面
function myclick(event) { var realName = document.getElementById('realName').value; if (event.key === "Enter") { console.log("kkkkkkkkkkkkk"); ys.ajax({ url: '@Url.Content("~/OrganizationManage/User/GetFormInfo")' + '?realName=' + realName, type: "get", success: function (obj) { if (obj.Tag == 1) { var result = obj.Data[0]; console.log("mobile:" + result.mobile); document.getElementById("mobile").value = result.mobile; } } }); } }
2、自定义类MyClass位置及代码
using System.Collections.Generic; using System.Data; using System.Text; using System.Threading.Tasks; using YiSha.Data.Repository; using YiSha.Util.Model; namespace YiSha.Service.MyService { public class MyClass: RepositoryFactory { public async Task<TData<DataTable>> GetTable(string strsql) { TData<DataTable> obj = new TData<DataTable>(); obj.Data = await this.BaseRepository().FindTable(strsql); obj.Total = obj.Data.Rows.Count; obj.Tag = 1; return obj; } public async Task<TData<DataTable>> GetTable(string strsql, Pagination pagination) { TData<DataTable> obj = new TData<DataTable>(); obj.Data = await this.BaseRepository().FindTable(strsql, pagination); obj.Total = pagination.TotalCount; obj.Tag = 1; return obj; } public async Task<bool> SetTable(string strSql) { var result = await this.BaseRepository().ExecuteBySql(strSql); return result > 0 ? true : false; } } }
3、在controller里
[HttpGet] [AuthorizeFilter("organization:user:view")] public async Task<TData<DataTable>> GetFormInfo(string realName) { MyClass myclass = new MyClass(); string sql = $@" SELECT UserName,Birthday,Mobile FROM sysuser WHERE realname='{realName}'"; TData<DataTable> obj = await myclass.GetTable(sql); return obj; }
标签:obj,realName,框架,前端,result,using,一沙,Data,string From: https://www.cnblogs.com/wishit/p/18663368