PDA

View Full Version : [CLOSED] Web Api & Ext.net



matrixwebtech
Mar 09, 2015, 6:35 PM
Hi
I am new to Web Api and try to web api with Ext.net Mvc .can you please give me some idea how I use web api's methods with ext.net.

I try with jQuery for my practice


<script>
var fun = function (type) {
$.ajax({
type: type,
url: "api/values?id=5&token=kkkkdjj",
// data: '{id: "5" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
// success: OnSuccess,
failure: function (response) {
// alert(response.d);

}


});
}
</script>
<body onload="fun('Get')">
<input type="button" onclick="fun('Delete')" value="Delete" />
<input type="button" onclick="fun('Put')" value="Put" />
</body>




public class ValuesController : ApiController
{

// GET api/values/5
public string Get(int id)
{
return "value";
}

// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}



// POST api/values
public void Post([FromBody]string value)
{
}

// PUT api/values/5
public void Put(int id, [FromBody]string value)
{
}

// DELETE api/values/5
public void Delete(int id,string token)
{

}
}
I pass type as parameter ,how I do this with ext.net controls like button .

Daniil
Mar 10, 2015, 7:44 AM
Hi @matrixwebtech,

I would try a method option.

Ext.net.DirectMethod.request({
url : "api/values?id=5&token=kkkkdjj",
cleanRequest : true,
json : true,
params : {
name : name
},
method: type
});

Please see all the available options in #6 here:
http://examples2.ext.net/#/Events/DirectMethods/Overview/