This question is locked. New answers and comments are not allowed.
Hi,
I thought I will test the waters on the Razor MVC code but I definitely am a bit green on this front. Was hoping someone can just easily point me in the right direction. I basically have the code below which shows fine but none of the paging or any other ajax related things are working. I am sure I need to somehow tell it to post to _FirstLook but could not figure this out from the examples.
In my Index.cxhtml I have the following code:
In the HomeController the following:
The NutritionDto
The back-end is ADO.Net EF
I thought I will test the waters on the Razor MVC code but I definitely am a bit green on this front. Was hoping someone can just easily point me in the right direction. I basically have the code below which shows fine but none of the paging or any other ajax related things are working. I am sure I need to somehow tell it to post to _FirstLook but could not figure this out from the examples.
In my Index.cxhtml I have the following code:
@model IEnumerable<
eSite.Calorie.Models.NutritionDto
>
@(Html.Telerik().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.Description).Width(100);
columns.Bound(o => o.Amount).Width(100);
columns.Bound(o => o.Serving).Width(100);
columns.Bound(o => o.Grams).Width(100);
columns.Bound(o => o.Kcal_100).Width(100);
columns.Bound(o => o.Kj_100).Width(100);
columns.Bound(o => o.Kcal_serving).Width(100);
columns.Bound(o => o.Kj_serving).Width(100);
})
.DataBinding(dataBinding =>
{
dataBinding.Ajax().Select("_FirstLook", "Grid").Enabled(true);
})
.Scrollable(scrolling => scrolling.Enabled(true))
.Sortable(sorting => sorting.Enabled(true))
.Pageable(paging => paging.Enabled(true))
.Filterable(filtering => filtering.Enabled(true))
.Groupable(grouping => grouping.Enabled(true))
.Footer(true)
)
In the HomeController the following:
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Nutrition Search";
return View(GetNutrition());
}
[GridAction]
public ActionResult _FirstLook()
{
return View(new GridModel(GetNutrition()));
}
private IEnumerable<
NutritionDto
> GetNutrition()
{
NutritionEntities entity = new NutritionEntities();
List<
NutritionDto
> list = new List<
NutritionDto
>(entity.EnergySearch("%soup%").Select(order => new NutritionDto
{
ID = order.NDB_No,
Description = order.Description,
Grams = order.g.ToString(),
Amount = order.Amount.ToString(),
Kcal_100 = order.kcal_100g.ToString(),
Kj_100 = order.kj_100g.ToString(),
Kcal_serving = order.kcal_serving.ToString(),
Kj_serving = order.kj_serving.ToString(),
Serving = order.Serving
}));
return list;
}
}
The NutritionDto
[KnownType(typeof(NutritionDto))]
public class NutritionDto
{
public string ID { get; set; }
public string Description { get; set; }
public string Amount { get; set; }
public string Serving { get; set; }
public string Grams { get; set; }
public string Kcal_100 { get; set; }
public string Kj_100 { get; set; }
public string Kcal_serving { get; set; }
public string Kj_serving { get; set; }
}
The back-end is ADO.Net EF