PDA

View Full Version : [CLOSED] MVC Gridpanel Form Post



MWM2Dev
May 16, 2013, 9:02 AM
Heya,

I have the following (Complex) Model:




namespace ReleaseManager.Models
{
using System;
using System.Collections.Generic;

using ReleaseManager.Database;

/// <summary>
/// The release model.
/// </summary>
public class ReleaseModel
{
/// <summary>
/// Initializes a new instance of the <see cref="ReleaseModel" /> class.
/// </summary>
public ReleaseModel()
{
this.Checklist = new ChecklistModel();
}

/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>
/// The title.
/// </value>
public string Title { get; set; }

/// <summary>
/// Gets or sets the description.
/// </summary>
/// <value>
/// The description.
/// </value>
public string Description { get; set; }

/// <summary>
/// Gets or sets the release date.
/// </summary>
/// <value>
/// The release date.
/// </value>
public DateTime ReleaseDate { get; set; }

/// <summary>
/// Gets or sets the projects.
/// </summary>
/// <value>
/// The projects.
/// </value>
public List<Project> Projects { get; set; }


/// <summary>
/// Gets or sets the projects.
/// </summary>
/// <value>
/// The projects.
/// </value>
public List<Project> SelectedProjects { get; set; }

/// <summary>
/// Gets or sets the checklists.
/// </summary>
/// <value>
/// The checklists.
/// </value>
public ChecklistModel Checklist { get; set; }

/// <summary>
/// Gets or sets the releases.
/// </summary>
/// <value>
/// The releases.
/// </value>
public List<Release> Releases { get; set; }
}
}



namespace ReleaseManager.Models
{
using System.Collections.Generic;

/// <summary>
/// The checklist model.
/// </summary>
public class ChecklistModel
{
/// <summary>
/// Initializes a new instance of the <see cref="ChecklistModel" /> class.
/// </summary>
public ChecklistModel()
{
this.Points = new List<PointModel>();
}

/// <summary>
/// Gets or sets the description.
/// </summary>
/// <value>
/// The description.
/// </value>
public string Description { get; set; }

/// <summary>
/// Gets or sets the points.
/// </summary>
public List<PointModel> Points { get; set; }
}
}



namespace ReleaseManager.Models
{
using System;

using Ext.Net;
using Ext.Net.MVC;

/// <summary>
/// The point model.
/// </summary>
[Model(Name = "CheckPoint")]
[JsonWriter(Encode = true, Root = "data")]
public class PointModel
{
/// <summary>
/// Gets or sets the description.
/// </summary>
public string Description { get; set; }

/// <summary>
/// Gets or sets the position.
/// </summary>
/// <value>
/// The position.
/// </value>
[Field(Ignore = true)]
public int Position { get; set; }

/// <summary>
/// Gets or sets the duration.
/// </summary>
[ModelField(Type = ModelFieldType.Date, DateFormat = "hh/mm")]
public TimeSpan Duration { get; set; }
}
}


Html.X().GridPanel().ID("checkpoint").Height(200).Store(Html.X().StoreFor(model => model.Checklist.Points)).ColumnModel(Html.X().RowN umbererColumn().Width(25).Text("#"), Html.X().ColumnFor(Model.Checklist.Points, model => model.Duration).ToBuilder<Column.Builder>().Width(100).Editor(Html.X().TimeField().AllowBla nk(false)), Html.X().ColumnFor(Model.Checklist.Points, model => model.Description).ToBuilder<Column.Builder>().Flex(1).Editor(Html.X().TextField().AllowBlank( false)))

And with a gridpanel I want to add Points to the ChecklistModel which is part of the ReleaseModel.
However on a standard MVC FormPost the Controller doesnt map the gridpanel to the Model.

So a few questions arise:
1) Is it even possible to databind a gridpanel in my controller to the ReleaseModel on a (standard)form submit?
2) If the above is not possible what would you recommand on how to bind the gridpanel in the controller?

Daniil
May 16, 2013, 10:53 AM
Hi @MWM2Dev,

There are two tasks.

1. Submitting a GridPanel's data.

A GridPanel's doesn't submit its data automatically.

To get it in POST you can put it to a Hidden field. You can do it just before submitting. To extract data from a GridPanel you can use its getRowsValues method.

There is also the useful submitData method if you want just submit a GridPanel's data. Please see the example.
http://examples2.ext.net/#/GridPanel/Miscellaneous/Submit_to_Handler/

2. Getting a GridPane's data within a controller as a Model instance.

You can use a ModelBinder attribute. Please follow this link for details.
http://forums.ext.net/showthread.php?24049&p=105622&viewfull=1#post105622

MWM2Dev
May 16, 2013, 12:10 PM
Thanks Daniil, worked like a charm!