Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Not working

HTML
@model Inspinia_MVC5.Models.Message

@{
    ViewBag.Title = "My chat";
}

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width" />
    <title>MyChat</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script>
    <link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css"
        rel="stylesheet" type="text/css" />

    <script type="text/javascript">
        $("#modelopen").live("click", function () {
            debugger;
            $("#window").dialog({
                title: "Send message",
                width: 430,
                height: 250,
                modal: true,
                buttons: {
                    Close: function () {
                        $(this).dialog('close');
                    }
                }
            });
            return false;
        });
    </script>
    <script type="text/javascript">


        function Send() {
            debugger;
            var sender = $("#txtSender").val();
            var receiver = $("#txtReceiver").val();
            var msg = $("#txtMsg").val();

            if (sender != '' && receiver != '' && msg != '') {
                $.ajax({
                    type: 'POST',
                    url: "@(Url.Action("SendMsg", "Mailbox"))",
                    dataType: 'json',
                    data: { Sender: sender, Receiver: receiver, Msg: msg },
                    success: function (data, textStatus, jqXHR) {
                        $("#txtSender").val('');
                        $("#txtReceiver").val('');
                        $("#txtMsg").val('');
                        $("#lblMsg").text('Message sent.');
                        $("#lblMsg").show();
                    },
                    error: function () {
                        alert('error');
                    }
                });
            }

        }

    </script>
</head>
<body>

    <div class="wrapper wrapper-content animated fadeInRight">


        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>Send Message</h5>
            </div>

            <div class="ibox-content">
                <div>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <br />
                        <button id="modelopen" class="btn btn-info">Open Dialog</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    @using (Html.BeginForm("Mychat", "Mailbox", FormMethod.Post, new { id = "SendMsg" }))
    {
        @Html.AntiForgeryToken()
        <div id="window" title="basic dialog model" style="display:none;" >

            <div class="form-horizontal">
                @Html.ValidationSummary(true)

                <div class="form-group">
                    @Html.LabelFor(model => model.UserName, new { @class = "control-label col-md-2" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(model => model.UserName, new { @id = "txtSender", @onclick = "HideSender();" })

                    </div>
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.Receiver, new { @class = "control-label col-md-2" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(model => model.Receiver, new { @id = "txtReceiver", @onclick = "HideReceiver();" })

                    </div>
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.MessageText, new { @class = "control-label col-md-2" })
                    <div class="col-md-8">
                        @Html.TextBoxFor(model => model.MessageText, new { @id = "txtMsg", @onclick = "HideMsg();" })

                    </div>

                </div>

                <div class="form-group">

                    <div class="col-md-8">
                        <input id="btnSend" type="button" value="Send" class="btn btn-info btn-sm" onclick="Send();" />
                    </div>
                </div>
                @Html.LabelFor(model => model.MessageText, new { @id = "lblMsg", style = "display: none;" })


            </div>


        </div>
    }
</body>
</html>
Posted
Updated 6-Apr-15 0:49am
v2

1 solution

This is Code use for Modal Dailog

XML
<div class="modal fade" id="itemModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel"> Create New Item</h4>
            </div>
            <div class="modal-body no-padding">
                @using (Ajax.BeginForm("CreateOrEditItem", "Item", new AjaxOptions { HttpMethod = "POST" }, new { @class = "smart-form" }))
                {
                    <div id="ItemModelContent">

                    </div>
                    <footer>
                        <input type="submit" id="btnAdd" name="Edit" value="Save" class="btn btn-primary" />
                        <input type="submit" value="Cancel" class="btn btn-default" data-dismiss="modal">
                    </footer>
                }
            </div>


        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>


Put This Jquery In your current Page
PHP
$('#createNew').on('click', function () {
            var url = '/Item/CreateOrEditItem';
            $.get(url, function (data) {
                $('#ItemModelContent').html(data);
                $('#itemModel').modal('show');
            });



In controller Action
SQL
public ActionResult CreateOrEditItem(Item ObjItem)
{
    return PartialView(_Creatmodel,ObjItem);
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900