Asp.net mvc json


Asp.net mvc json



I am working on a mvc project, and having problem with json.

i have created a demo project with list of colors

    public JsonResult GetResult()     {         List<string> strList = new List<string>();         strList.Add("white");         strList.Add("blue");         strList.Add("black");         strList.Add("red");         strList.Add("orange");         strList.Add("green");         return this.Json(strList);     } 

i am able to get these on my page, but when i try to delete one color, that is when i send the following using jquery

function deleteItem(item) {         $.ajax({             type: "POST",             url: "/Home/Delete/white",             data: "{}",             contentType: "application/json; charset=utf-8",             success: ajaxCallSucceed,             dataType: "json",             failure: ajaxCallFailed         });     } 

the controler action

public JsonResult Delete(string Color) {}

Color always returns null, even if i have specified "/Home/Delete/white" in the url.

i know i am doing something wrong or missing something, but not able to find out what.

please can any one guide me in the right direction.


WebDev.WebServer.EXE hangs

1:

Model Binding to a List in asp.net mvc 2. Found example. Can't find where I'm going wrong
Just a common public opinion: It's very strange to Pascal-case method parameters as you do.... ASP.NET MVC User Control - Where to put the CSS specific to a control?

The simplest quick fix to your problem

Renaming your controller action parameter to id would did the trick just fine (in case your default route is defined as {controller}/{action}/{id}). ajax.actionlink. Is ADO.NET Entity Framework (with ASP.NET MVC v2) a viable option when writing custom and contantly updated websites?
[HttpPost] public JsonResult Delete(string id) {     // did  what's required } 

Don't forreceive around attrialthough es

And don't forreceive to put the attrialthough e on your action method, otherwise a web crawler would be able to delete all your colour entries.. How to disable VS compile warning “class or css class is not defined” Either use HttpPost or even better HttpDelete, for the reason this you did use Ajax request anyway, so you must issue a DELETE request.. patterns to use when building complex web UI
Validation not firing even when my form is obviously invalid

2:

Try changing your url to:. "/Home/Delete?Color=white". The reason is this there isn't a route set up to handle a string called color, like you have.. Have a look at this for info on how to create a custom route this will handle your current url format.. http://www.asp.net/mvc/tutorials/creating-custom-routes-cs.

3:

Check your routes. (Usually set in /global.asax.).

4:

try this above the default.
routes.MapRoute("Color", "{controller}/{action}/{color}", new { controller = "Home", action = "Index", Color = "" });  


62 out of 100 based on 17 user ratings 592 reviews

@