Awesome ASP.net Core and MVC Controls

Init Call




The InitCall html helper initiates a server call that can be executed using awe.oc(name, opt) js function, similar to awe.open(name, opt) used for opening popups.
CallDemo/Index.cshtml
@Html.Awe().InitCall("callHi").Url(Url.Action("SayHi")).Success("echo")
@Html.Awe().InitCall("callName").Url(Url.Action("SayName")).Parent("txtName", "name").Success("echo")
@Html.Awe().InitCall("callName2").Url(Url.Action("SayName")).Parent("txtName", "name")

<p>
<button type="button" class="awe-btn" onclick="awe.oc('callHi')">Click to call</button>
</p>
<p>
<button type="button" class="awe-btn" onclick="awe.oc('callName', { params: { id: 15 } })">Call with parameters</button>
<button type="button" class="awe-btn foo">Call 2</button>
</p>

@Html.Awe().TextBox("txtName").Placeholder("write a name here").Value("Art Vandelay")

<script>
function echo(res) {
awe.flash(awem.notif(res));
}

$(function() {
$(document).on('click', '.foo', function() {
var btn = $(this);
var xhr = awe.oc('callName2', { params: { id: 20 } });

$.when(xhr).done(function(res) {
var msg = $('<span> ' + res + '</span>');
btn.after(msg);
awe.flash(msg);
setTimeout(function () {
msg.fadeOut(function () { msg.remove(); });
}, 1000);
});
});
});
</script>
Demos/Helpers/CallDemoController.cs
public class CallDemoController : Controller
{
public ActionResult Index()
{
return View();
}

public string SayHi()
{
return "server says hi";
}

public string SayName(string name, int id)
{
return "my name is " + name + "; id = " + id;
}
}



Comments

We use cookies to improve your online experience. By accessing this site, you agree to the use of cookies and other technologies to process your personal data (e.g. IP address) to enhance and personalise your experience across our websites. Additionally, third-party companies, may store cookies on your device and use similar technologies to collect and use certain information. For more information, refer to our privacy policy and cookie policy.