146
rated 0 times
[
153]
[
7]
/ answers: 1 / hits: 7528
/ 5 Years ago, mon, september 9, 2019, 12:00:00
I am trying to get user input in button click
.
When user insert number and press Check
, it needs to return xml
data type.
So in my controller
I create function
which will return a data for passing ID
[ResponseType(typeof(AKONTA))]
public IHttpActionResult GetAKONTA(string id)
{
AKONTA aKONTA = db.AKONTAS.Find(id);
if (aKONTA == null)
{
return BadRequest(Ne postoji A_KONTO pod tim rednim brojem);
}
return Ok(aKONTA);
}
And In my View I have following
<br /><br />
<form>
<div class=form-group>
<label>A_KONTO</label>
<input type=text class=form-control aria-describedby=AKONTO BROJ placeholder=Unesite broj AKONOTO>
</div>
<div class=form-group>
<a asp-action=Index class=btn btn-primary id=aKonto [email protected](GetAKONTA, Akontas)>Provjeri</a>
</div>
</form>
And I want to create in btn
click
when user pass ID
it needs to return XML
data format.
SO far I create a JS
function, but I don't know JavaScript
and don't know the logic how to pass Controller Action Result
to JS
.
<script>
$(document).ready(function () {
$('#aKonto').click(function () {
document.getElementById(aKonto).onclick = function () {GetAKONTA()};;
});
});
</script>
If someone can help me I would be very thankful.
Cheers !
UPDATE
function aKontoSubmit() {
$.ajax({
type: GET,
url: 'api/Akontas',
//data: { id: id },
dataType: xml,
success: function (result) {
// action to do after form submit
},
error: function () {
alert(Ne postoji AKONTO pod tim rednim brojem);
}
});
}
**routeConfig**
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace AkontasWebApi
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute({resource}.axd/{*pathInfo});
routes.MapRoute(
name: Default,
url: {controller}/{action}/{id},
defaults: new { controller = Home, action = Index, id = UrlParameter.Optional }
);
}
}
}
More From » asp.net-mvc