controller:
using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis.Options;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;
using System;
namespace ResumeManager.Controllers
{
public class DropDownController : Controller
{
public IActionResult Index()
{
return View();
}
public JsonResult AjaxPostCall(string staffid)
{
cartype client = new cartype
{
typename = "<select name=\"type\" id=\"type\"><option value =" + '"' + "su" + '"' + "> suv </option >" +
"<option value = " + '"' + "sedan" + '"' + "> sedan </option >" +
"<option value =" + '"' + "truck" + '"' + "> truck </option >" +
"<option value =" + '"' + "jeep" + '"' + "> jeep </option ></select>" //_context.Parameters.FromSqlRaw("exec s_StaffDeposit @MainCode", flagParam).ToString()//(car.ToString()) //"Best Of The Best"
};
return Json(client);
}
public class cartype
{
public string typename
{
get;
set;
}
}
}
}
view:
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}
<select name="cars" id="cars">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
@*<select name="type" id="type">
@*<option value="suv">suv</option>
<option value="sedan">sedan</option>
<option value="truck">truck</option>
<option value="jeep">jeep</option>
</select>*@
<p1 id="destry"</p1>
<script>
document.addEventListener('DOMContentLoaded', function () {
document.querySelector('#cars').onchange = () => {
$.ajax({
type: "POST",
url: "/DropDown/AjaxPostCall", //publish garda agadi ko / rakhne dev ma narakhne..publish garda appnamerakhne dev ma narakhne
data: { "clientdata": $("#cars").val() },
//contentType: "application/json; charset=utf-8",
//dataType: "json",
success: function (response) {
if (response.typename != null) {
alert("bellopww");
console.log(response.typename);
document.querySelector('#destry').innerHTML = response.typename;
//console.log(response);
//document.querySelector('#MainCode').value = response.name;
//$('#Name').val(response.name)
//alert("Name : " + response.Name + ", Designation : " + response.Designation + ", Location :" + response.Location);
} else {
alert("Something went wrong");
}
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
}
});
</script>
Comments
Post a Comment