In my app I am sending post request with string value with Jquery, then in controller, passed string value is used to get some data from API.
Next controller returns a view and model with data from API inside. That data from model I want to put inside values of few textboxes.
The main problem is that I dont know how to refresh that div with model values. When I used post form without jquery and ajax it works but I want to do it asynchronous.
Js script with post request:
<script type="text/javascript">
$(document).ready(function () {
$('#btn').click(function () {
var data1 = $('#textBox').val();
$.ajax({
url: '/Home/Fill',
type: 'POST',
dataType: 'string',
data: { number:data1 },
success: function (data) {
}
});
});
});
Controller:
[HttpPost]
public ActionResult Fill(string number)
{
CompanyInfo Info = new CompanyInfo();
//Here some API actions
return View("Index",Info);
}
Div with model values inside the Index view:
<div id="target">
<h1>Number:</h1>
<input type="text" value="@Html.DisplayFor(m => m.Num)" id="Number" />
<br />
<h1>Company name:</h1>
<input type="text" value="@Html.DisplayFor(m=>m.CompanyName)" id="CompanyName" />
<br />
<h1>Street Address</h1>
<input type="text" value="@Html.DisplayFor(m=>m.StreetAddress)" id="Address" />
</div>