你好我用asp.net mvc 4开发一个应用程序,并且我使用kendo添加DataGridView! 我有一些麻烦:
我想在datagridview
中为列添加两个属性我有一个模特"用户"和模型"项目" 当用户创建新项目时,我必须将他的姓名和姓氏添加到datagridview 这是我的界面:
[
这是我的控制者:
public ActionResult Projet_Read([DataSourceRequest]DataSourceRequest request)
{
var projets = (from a in db.Projets
join b in db.Utilisateurs on a.UtilisateurID equals b.UtilisateurID
select new
{
ProjetId=a.ProjetId,
nomP=a.nomP,
DateDebut=a.DateDebut,
DateFinPrevue=a.DateFinPrevue,
DateFinReele=a.DateFinReele,
etat=a.etat,
Description=a.Description,
U=b.Prenom // U=b.Prenom +" "+b.Nom
});
DataSourceResult result = projets.ToDataSourceResult(request, projet1 => new
{
ProjetId = projet1.ProjetId,
nomP = projet1.nomP,
DateDebut = projet1.DateDebut,
DateFinPrevue = projet1.DateFinPrevue,
DateFinReele = projet1.DateFinReele,
Description = projet1.Description,
etat = projet1.etat,
U=projet1.U
});
return Json(result);
}

这是我的观点:
<legend class="legend">Tous Les Projets</legend>
@{
Layout = "~/Views/Shared/admin.cshtml";
}
<link href="~/Content/Gridmvc.css" rel="stylesheet" />
<script src="~/Scripts/gridmvc.js"></script>
<script src="~/Scripts/gridmvc.min.js"></script>
<div class="container-fluid placeholders">
<div style="height:850px">
@(Html.Kendo().Grid<mvc_depences.Models.Projet>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.U).Title("Chef de Projet").Width(145);
columns.Bound(c => c.nomP).Title("Nom Projet");
columns.Bound(c => c.DateDebut).Title("Date Debut");
columns.Bound(c => c.DateFinPrevue).Title("Date Fin Prevue");
columns.Bound(c => c.DateFinReele).Title("Date Fin Réelle");
columns.Bound(c => c.etat).Title("Etat");
columns.Bound(c => c.Description).Title("Description");
columns.Command(command => { command.Edit().Text("Modifier"); }).Width(150);
})
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Pageable()
.Selectable(selectable =>
{
selectable.Mode(GridSelectionMode.Single);
selectable.Type(GridSelectionType.Row);
})
.Filterable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.ProjetId))
.Read(read => read.Action("Projet_Read", "Projet"))
.Update(update => update.Action("Projet_Update", "Projet"))
)
)
</div>
</div>
&#13;
答案 0 :(得分:1)
嗯,我没有使用过Kendo UI的经验。我的猜测是你尝试在SQL查询中连接字符串。您可以尝试首先获取所有数据(包括姓氏和姓氏)并将其映射到您的视图中。
控制器:
@app.route('/callback')
def callback_handling():
env = os.environ
code = request.args.get('code')
json_header={'Content-Type': 'application/x-www-form-urlencoded'}
token_url = "https://{domain}/oauth/token".format(domain='mydomain')
token_payload = {
'client_id': 'myid',
'client_secret': 'mysecret',
'redirect_uri': 'http://localhost:8080/callback',
'code': code,
'grant_type': 'authorization_code'
}
encoded = urllib.urlencode(token_payload)
user_url = "https://{domain}/userinfo?access_token={access_token}"\
.format(access_token=token_info['access_token'])
user_info = urlfetch.Fetch(user_url, method=urlfetch.GET, headers=json_header)
session['profile'] = user_info
return redirect('/dashboard')
在视图中:
public ActionResult Projet_Read([DataSourceRequest]DataSourceRequest request)
{
var projets = (from a in db.Projets
join b in db.Utilisateurs on a.UtilisateurID equals b.UtilisateurID
select new
{
ProjetId = a.ProjetId,
nomP = a.nomP,
DateDebut = a.DateDebut,
DateFinPrevue = a.DateFinPrevue,
DateFinReele = a.DateFinReele,
etat = a.etat,
Description = a.Description,
Prenom = b.Prenom,
Nom = b.Nom
});
DataSourceResult result = projets.ToDataSourceResult(request, projet1 => new
{
ProjetId = projet1.ProjetId,
nomP = projet1.nomP,
DateDebut = projet1.DateDebut,
DateFinPrevue = projet1.DateFinPrevue,
DateFinReele = projet1.DateFinReele,
Description = projet1.Description,
etat = projet1.etat,
Prenom = projet1.Prenom,
Nom = projet1.Nom
});
return Json(result);
}
这应该可以解决问题
答案 1 :(得分:1)
我刚刚在sql请求中进行了连接,并且我保持其他代码不变!
public ActionResult Projet_Read([DataSourceRequest]DataSourceRequest request)
{
var projets = (from a in db.Projets
join b in db.Utilisateurs on a.UtilisateurID equals b.UtilisateurID
select new
{
ProjetId=a.ProjetId,
nomP=a.nomP,
DateDebut=a.DateDebut,
DateFinPrevue=a.DateFinPrevue,
DateFinReele=a.DateFinReele,
etat=a.etat,
Description=a.Description,
U=b.Prenom +" "+ b.nom
});
DataSourceResult result = projets.ToDataSourceResult(request, projet1 => new
{
ProjetId = projet1.ProjetId,
nomP = projet1.nomP,
DateDebut = projet1.DateDebut,
DateFinPrevue = projet1.DateFinPrevue,
DateFinReele = projet1.DateFinReele,
Description = projet1.Description,
etat = projet1.etat,
U=projet1.U,
});
return Json(result);
}