I've written an autohosted-app to show a few data that are in a list.
To get the data in the list, I use this piece of code with a CAML Query.
using (var clientContext = TokenHelper.GetClientContextWithContextToken(hostWeb, contextToken, Request.Url.Authority))
{
var web = clientContext.Web;
var list = web.Lists.GetByTitle("Calendrier");
string camlString =
"<View><ViewFields>" +
"<FieldRef Name='Title' />" +
"<FieldRef Name='EventDate' />" +
"<FieldRef Name='Category' />" +
"<FieldRef Name='Location' />" +
"<FieldRef Name='Eleve' />" +
"</ViewFields></View>";
var camlQuery = new Microsoft.SharePoint.Client.CamlQuery() { ViewXml = camlString };
// allItems contains the data
var allItems = list.GetItems(camlQuery);
clientContext.Load(allItems);
clientContext.ExecuteQuery();
clientContext.Dispose();
return View(allItems.ToList());
}
And here is the code in the view to print the data retrieved :
@foreach (var item in Model)
{
<tr>
<td>@item["EventDate"]</td>
<td>@item["Location"]</td>
<td>@item["Eleve"]</td>
<td>@item["Category"]</td>
</tr>
}
But when I try to print the Eleve field in my View, everything went fine except for printing the "Eleve" column which is a lookup.
How can I get the lookup value of Eleve.Title instead of it to print 'Microsoft.SharePoint.Client.FieldLookupValue' in the column where I try to print @item["Eleve"]?
And if somebody have a good link to learn CAML for sharepoint 2013 thanks to share it :)