PDA

View Full Version : [CLOSED] StoreForModel : Get grid values in controller method as list of object



matrixwebtech
May 19, 2015, 6:05 AM
Hi
I have a question ,I prepare a grid with StoreforModel and try to get grid value on submit button click as list of object in controller action ,Is it possible?


@model e.Controllers.StoreforModelEmployee
@{
var X=Html.X();

}
<script>
function fullNameBuilder(value, record) {
return record.data.LastName + ', ' + record.data.FirstName;
}
</script>
<h1>Store for Model</h1>
<p>Automatically build store for a model</p>
@Html.X().ResourceManager()
@(
@X.FormPanel()
.ID("f")
.Items
(
Html.X().GridPanel()
.Title("Employees")
.Width(500)
.Height(200)
.ForceFit(true)
.Plugins(X.CellEditing())
.Store(
Html.X().StoreFor<e.Controllers.StoreforModelEmployee>()
)
.ColumnModel(
Html.X().ColumnFor(m => m.Id).ToBuilder<Column.Builder>().Width(30),
Html.X().Column().DataIndex("FullName").Text("Full Name").Editor(X.TextField()),
Html.X().ColumnFor(m => m.FirstName),
Html.X().ColumnFor(m => m.LastName)
)


)
.Buttons(
X.Button()
.Text("Submit")
.DirectEvents(d=>{
d.Click.FormID = "f";
d.Click.Action = "submit";
})
)
)


public class StoreforModelController : Controller
{
//
// GET: /StoreforModel/

public ActionResult Index()
{
return View();
}

public ActionResult GetEmployees()
{
return this.Store(StoreforModelEmployee.GetAll());
}
public void submit(List<StoreforModelEmployee> _StoreforModelEmployee)
{
}

}

[Proxy(Read = "~/StoreforModel/GetEmployees")]
[JsonReader(Root = "data")]
[VirtualModelField(Name = "FullName", ConvertHandler = "fullNameBuilder")]
// [ClientResource(Path = "~/Areas/Models/Content/storeHelpers.js")]
public class StoreforModelEmployee
{
[ModelField(IDProperty = true)]
public int Id
{
get;
set;
}

public string FirstName
{
get;
set;
}

public string LastName
{
get;
set;
}

[ModelField(Ignore = true)]
public string IgnoreField
{
get;
set;
}

public static List<StoreforModelEmployee> GetAll()
{
return new List<StoreforModelEmployee> {
new StoreforModelEmployee{ Id = 1, FirstName = "John", LastName = "Snow"},
new StoreforModelEmployee{ Id = 2, FirstName = "Fred", LastName = "Flintstone"},
new StoreforModelEmployee{ Id = 3, FirstName = "Andrew", LastName = "Fuller"}
};
}
}

I need the list in submit method as parameter.

also I found there are no DateColumnFor option ,so how I manage date with Storefor approach?
How I define IdProperty ?

Daniil
May 19, 2015, 10:29 PM
Hi @matrixwebtech,

A GridPanel's data doesn't go with a form submit. So, you need to send a GridPanel's data via a DirectEvent's ExtraParams. You can grab a GridPanel's data via .getRowsValues() call.

In a controller you'll need to define an action like:

public ActionResult(string jsonData)
{
Ext.Net.SubmitHandler submitHandler = new Ext.Net.Submit(jsonData);
List<TheEntityClass> data = submitHandler.Object<TheEntityClass>();
...
}

The jsonData parameter name should match the name of the DirectEvent's parameter that you defined in ExtraParams.


also I found there are no DateColumnFor option ,so how I manage date with Storefor approach?
How I define IdProperty ?

Please start a new forum thread(-s).