Home Show Model Information In mvc view using handlebars
Reply: 0

Show Model Information In mvc view using handlebars

John Doe
1#
John Doe Published in 2017-12-07 12:19:38Z

Show model information in mvc view, i am new to handle bars. I want to show the information of the model using handlebars.

I have a Ajax call which return a model information on success i want to bind the template with the data.

However, i am not getting success.

My Effort is below.

<html lang="en">
<head>

    <script src="~/scripts/jquery-1.10.2.min.js"></script>
    <script src="~/scripts/handlebars.min.js"></script>

    <title> HandleBar Practice</title>
</head>
<body>

    <script id="message-response-template" type="text/x-handlebars-template">

        <div>
            My FirstName Is: {{FirstName}}
        </div>
        <div>
            My MiddleName Is: {{MiddleName}}
        </div>
        <div>
            My Address Is: {{Address}}
        </div>
        <div>
            My PhoneNumber Is: {{PhoneNumber}}
        </div>
        <div>
            My CNIC Is: {{CNIC}}
        </div>



    </script>
</body>
</html>
<script>
    $(document).ready(function () {
        alert('document ready');
        $.ajax({
            type: "POST",
            url: "AjaxCall",
            data: '{ sendData: "ok" }',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                console.log(result);
                var templateResponse = Handlebars.compile($("#message-response-template").html());
                templateResponse(result);
            }
        });
    });



</script>

Output

Browser Console

Handlebars.compile($("#message-response-template").html())
ƒ e(a,b){return g||(g=d()),g.call(this,a,b)}

var templateResponse = Handlebars.compile($("#message-response-template").html());

undefined //it display undefined i am not getting the idea what's wrong

Source

[HttpPost]
        public ActionResult AjaxCall(string sendData)
        {

            return Json(new Employee() { FirstName = "John", MiddleName = "N/A", LastName = "DOE", CNIC = "123234234", Address = "Pakistan" }, JsonRequestBehavior.AllowGet);
        }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.30251 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO