I am trying to use the grid with a colorpicker to set a colorcode property on my model and even so the column is bound, I can never see the updated code when the model is sent to the controller. I am using the standard in line editing function of the grid. (which manages to update teh model for simple properties.
CSHTML
@(Html.Kendo().Grid<Tetral.Services.Entities.AllocationPortfolioEntity>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.ColourCode).Title("Colour").Width("84px").ClientTemplate("<span style='display: inline-block; width: 100%; height: 100%; background-color: #= ColourCode #'> </span>");
columns.Command(m =>
{
m.Edit();
m.Destroy();
}).Width(260);
})
.HtmlAttributes(new { style = "height:850px;width:100%" })
.BindTo(@Model)
.Scrollable(scr => scr.Enabled(true))
.DataSource(dataSource => dataSource
.Ajax()
.Model(m => m.Id(p => p.Id))
.Create(update => update.Action("AllocationPortfolioInsert", "DataManagement"))
.Update(update => update.Action("AllocationPortfolioUpdate", "DataManagement"))
.Destroy(update => update.Action("AllocationPortfolioDelete", "DataManagement"))
)
TEMPLATE
@model string
@(Html.Kendo().ColorPickerFor(m => m)
//.Palette(ColorPickerPalette.Basic)
.Name("ColourPicker")
.Events(e => e.Change("colourPickerChange"))
)
MODEL
private string colourCode;
[UIHint("ColourPicker")]
public string ColourCode
{
get { return colourCode; }
set { this.colourCode = newValue;}
}
The control manages to bind and show the value from my model, but when I submit the form, the model in my controller does not show the updated value from the editor.
I have tried using a normal @Html.EditorFor() and this works as expected. (ie I see the updated value)
@model GeneralDisclosureEntity
@using (Html.BeginForm("GeneralDisclosureTextUpdate", "DataManagement", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div hidden="hidden">
@Html.EditorForModel()
</div>
@(Html.Kendo().EditorFor(m => m.HTML)
.Name("Content")
.HtmlAttributes(new { style = "width:100%;height:440px" })
.Encode(false)
.Tools(t => t.Clear()
.Bold()
.Italic()
.Underline()
.Strikethrough()
.JustifyLeft()
.JustifyCenter()
.JustifyRight()
.JustifyFull()
.InsertUnorderedList()
.InsertOrderedList()
.Indent()
.Outdent())
)
<br />
<button id="btnSubmit3" type="submit" style="float:right")>Save Text</button>
}
Hi There
I've been trying to get this right, and none of the demos or forums posts appear to really give me a clear answer.
I'm trying to populate a dropdownlist from a related table (Foreign Key), and I'm getting a "Value cannot be null" error.
Here's the scenario:
I have a Courses and Cities table, defined like this,
public
class
City
{
[Key]
[ScaffoldColumn(
false
)]
public
int
CityId {
get
;
set
; }
[Required]
[DisplayName(
"City Name"
)]
public
string
CityName {
get
;
set
; }
public
virtual
ICollection<Course> Courses {
get
;
set
; }
}
and this:
public
class
Course
{
[Key][ScaffoldColumn(
false
)]
public
int
CourseId {
get
;
set
; }
[Required]
public
string
CourseName {
get
;
set
; }
[ForeignKey(
"City"
)]
[UIHint(
"GridForeignKey"
)]
public
int
CityId {
get
;
set
; }
public
virtual
City City {
get
;
set
; }
[Required]
[DisplayName(
"Course Rating"
)]
[Range(0, 10)]
public
double
CourseRating {
get
;
set
; }
[Required]
[DisplayName(
"Course Par"
)]
public
double
CoursePar {
get
;
set
; }
[DisplayName(
"Course Map Co-ords"
)]
public
string
CourseMap {
get
;
set
; }
[DisplayName(
"Course Notes"
)]
public
string
CourseNotes {
get
;
set
; }
public
virtual
ICollection<GolfRound> GolfRounds {
get
;
set
; }
}
So, clearly it's just a Golf Score app I'm using to help me learn.
I've scaffolded the Controller and Views using Kendo Scaffolder, and ended up with this:
public
class
CourseController : Controller
{
private
GolfContext db =
new
GolfContext();
public
ActionResult Index()
{
return
View();
}
public
ActionResult Courses_Read([DataSourceRequest]DataSourceRequest request)
{
IQueryable<Course> courses = db.Courses;
DataSourceResult result = courses.ToDataSourceResult(request, course =>
new
{
CourseId = course.CourseId,
CourseName = course.CourseName,
CourseRating = course.CourseRating,
CoursePar = course.CoursePar,
CourseMap = course.CourseMap,
CourseNotes = course.CourseNotes
});
return
Json(result);
}
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult Courses_Create([DataSourceRequest]DataSourceRequest request, Course course)
{
if
(ModelState.IsValid)
{
var entity =
new
Course
{
CourseName = course.CourseName,
CourseRating = course.CourseRating,
CoursePar = course.CoursePar,
CourseMap = course.CourseMap,
CourseNotes = course.CourseNotes
};
db.Courses.Add(entity);
db.SaveChanges();
course.CourseId = entity.CourseId;
}
return
Json(
new
[] { course }.ToDataSourceResult(request, ModelState));
}
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult Courses_Update([DataSourceRequest]DataSourceRequest request, Course course)
{
if
(ModelState.IsValid)
{
var entity =
new
Course
{
CourseId = course.CourseId,
CourseName = course.CourseName,
CourseRating = course.CourseRating,
CoursePar = course.CoursePar,
CourseMap = course.CourseMap,
CourseNotes = course.CourseNotes
};
db.Courses.Attach(entity);
db.Entry(entity).State = EntityState.Modified;
db.SaveChanges();
}
return
Json(
new
[] { course }.ToDataSourceResult(request, ModelState));
}
and for the View:

@(Html.Kendo().Grid<
GolfScoreMVC.Models.Course
>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.CourseName);
columns.Bound(c => c.CourseRating);
columns.Bound(c => c.CoursePar);
columns.Bound(c => c.CourseMap);
columns.Bound(c => c.CourseNotes);
columns.ForeignKey(c => c.City, ( System.Collections.IEnumerable ) ViewData["Cities"], "CityId", "CityName");
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(180);
})
.ToolBar(toolbar =>
{
toolbar.Create();
})
.Editable(editable => editable.Mode(GridEditMode.PopUp))
.Pageable()
.Sortable(sortable =>
{
sortable.SortMode(GridSortMode.SingleColumn);
})
.Filterable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Model(model => model.Id(p => p.CourseId))
.Read(read => read.Action("Courses_Read", "Course"))
.Create(create => create.Action("Courses_Create", "Course"))
.Update(update => update.Action("Courses_Update", "Course"))
.Destroy(destroy => destroy.Action("Courses_Destroy", "Course"))
)
)
Now, initially the CityId column was not scaffolded at all, but in the Create popup, I got a CityId input field.
I added the "columns.ForeignKey(c => c.City, ( System.Collections.IEnumerable ) ViewData["Cities"], "CityId", "CityName");" part to try and produce a dropdownlist, but I'm not getting it right.
I'm using the default GridForeignKey template template file, and when rendering this, is where the error comes in.
Please help me. The standard demo here confuses me even more.
Am I supposed to create a list of the Cities first, like this?
private
GolfContext db =
new
GolfContext();
public
ActionResult Index()
{
IList<City> myCities = db.Cities.ToList();
ViewData[
"Cities"
] = myCities;
return
View();
}
That doesn't work either. I'm clearly missing some obvious and simple step.
Regards
JohannS
I have a very basic model bound grid with edit and destroy commands.
When the grid is in Edit mode, I press the cancel button and I expect the row to stay the same as before, however the grid deletes the row? I have verified that it is not invoking any destroy methods
I have a problem with too small X button to close a modal window when my web site is viewed on tablet computers.
Using KendoUI with MVC. I have a window like this:
@(Html.Kendo().Window().Name("​mywindow").Title("​My very own Window Title text")
.Content("Loading...").Iframe(true).Width(600).Height(300).Visible(false).Modal(true)
)
What I want to do is make the title text and especially the X to close the window about 2x bigger to make it easier to use on tabled computers. I this possible? If so, how?
Hi.
Is it possible to open detail template for a grid in windows? not in child grid.
May be it is custom command for grid's row, but not sure in how do that.
How do you set focus for the Html.Kendo().MultiSelectFor in javascript?
How do you set focus to the Html.Kendo().DatePickerFor in javascript?