This is a migrated thread and some comments may be shown as answers.

Can't call POST methods when using MVC wrapper

2 Answers 488 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jark Monster
Top achievements
Rank 1
Jark Monster asked on 30 Jul 2012, 06:05 PM
When using the following view code, I can't seem to find where I should be setting the type to POST so that it will reach back to the controller methods. 

Right now, if I put the [HttpPost] tag above the method, I get a 404 Not found error when I execute that method.  If I don't have the post tag, then I reach the method but the parameters are empty (Not null, just an empty, but instantiated object).

All of the examples I've seen have [HttpPost] or [AcceptVerbs(HttpVerbs.Post)] above the method.  I've tried both and can't get it to work.

Error:
HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.


Controller:
//Other CRUD omitted for brevity
        [HttpPost]
        public ActionResult CreateProducts([DataSourceRequest]DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<Models.ItemModel> itemsToAdd)
        {
            Models.ShipmentModel shipmentModel = SessionModel;
 
            foreach (Models.ItemModel newItem in itemsToAdd)
            {
 
                if (shipmentModel.ItemModelList.Count > 0)
                {
                    var nextID = (from i in shipmentModel.ItemModelList
                                  select i.ItemID).Max() + 1;
 
                    newItem.ItemID = nextID;
                }
 
                shipmentModel.ItemModelList.Add(newItem);
            }
 
            var items = shipmentModel.ItemModelList;
            DataSourceResult result = items.ToDataSourceResult(request);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

View
<div id="ShipmentForm">
@(Html.Kendo().Grid<KendoUITestEnvironment.Models.ItemModel>()
    .Name("QuoteItemGrid")
    .Columns(columns =>
    {
        columns.Bound(i => i.FreightClass).Width(50);
        columns.Bound(i => i.Length).Width(50);
        columns.Bound(i => i.Width).Width(50);
        columns.Bound(i => i.Height).Width(50);
        columns.Bound(i => i.DimensionUnitOfMeasure).Width(50);
        columns.Bound(i => i.QuantityValue).Width(50);
        columns.Bound(i => i.QuantityUnitOfMeasure).Width(50);
        columns.Bound(i => i.Weight).Width(50);
        columns.Bound(i => i.WeightUnitOfMeasure).Width(50);
        columns.Bound(i => i.NmfcCode).Width(50);
        columns.Bound(i => i.ItemDescription).Width(50);
        columns.Command(command => command.Destroy()).Width(110);
    })
    .ToolBar(toolbar =>
    {
        toolbar.Create();
        toolbar.Save();
    })
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Pageable()
    .Sortable()
    .Scrollable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .ServerOperation(false)
        .Events(events => events.Error("QuoteItemGrid_ErrorHandler"))
        .Model(model =>
        {
            model.Id(i => i.ItemID);
            model.Field(i => i.FreightClass);
        })
        .Create(create => create.Action("CreateProducts", "Home"))
        .Read(read => read.Action("GetProducts", "Home"))
        .Update(update => update.Action("UpdateProducts", "Home"))
        .Destroy(destroy => destroy.Action("DeleteProducts", "Home"))
    )
)
</div>

2 Answers, 1 is accepted

Sort by
0
Jark Monster
Top achievements
Rank 1
answered on 31 Jul 2012, 02:01 PM
I got the issue resolved.  There is apparently some difference between the Kendo UI Open source version and the 30 day free trial version.

I downloaded the 30 day trial and then pulled everything out of my solution and re-added and it worked.  I think the special case here is that I am using the ASP NET MVC wrapper, and I'm not sure if that was entirely present in the open source version since a few of the files are different and some of the existing files are of different sizes.

Hopefully this helps someone else, and saves them 4 days worth of banging their head against the wall.

I'll admit, I'm really looking forward to some comprehensive aspnet mvc wrapper documentation, but I know it's a WIP right now.

Also, for anyone's future consideration, there is aspnet mvc wrapper example projects (INCLUDING CONTROLLER CODE) in the 30 day free trial download.  This was not in the open source download (at least when I downloaded it, it wasn't).  Finding that, was an absolute lifesaver!
0
im
Top achievements
Rank 2
answered on 01 Aug 2012, 09:55 PM
Well if the Free trial works better for you Im happy to hear it.

However I have the commercial version and have the exact same problem. However in the .Datasource theres a .Type property you can set to HttpVerbs.Post

.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action(.....)
.Type(HttpVaebs.Post))
)

It helped me to get it to use the POST method, HOWEVER, now the sorting will not work. WHen it does post the sort parameter gets broken apart into 2 fields instead of one.. the col and direction. When this happens the binting to the DataSourceRequest doesnt pick up the the sort order info....

Anyone else seem to find the fix, before I start diving into the examples generated code differences from mine??? Even though the examples work fine, my code all but looks identical. (With the exception I have to put in the POST, orelse its just the Get)

Thanks

 

 

Tags
Grid
Asked by
Jark Monster
Top achievements
Rank 1
Answers by
Jark Monster
Top achievements
Rank 1
im
Top achievements
Rank 2
Share this question
or