1

This is my json function

  function getMessage(userId) {
                    $.ajax(
                         {

                             url: "@Url.Action("_getMessage")",
                             //url: "/Message/_getMessage",
                             type: "POST",
                             dataType: "json",
                             traditional: true,
                             data: { "recieverUsersId": userId },
                             success: function (response) {
                                 //alert("clicked");
                                 //loop the data.. how do I loop json?
                                 var div = $('#msg');
                                 var recieverImgDiv = $('.reciever')
                                 div.html("");
                                 div.html(response);
                                 alert('Success');
                         },
                         error: function (req, status, error) {
                             var div = $('#comment');
                             div.html("");
                             div.append('Error');
                             alert('Error');
                         }
                     });
         }

and this is my controller

 public ActionResult _getMessage(long recieverUsersId)
        {
            ViewBag.sentTime = "";

            long userId = WebSecurity.GetUserId(User.Identity.Name);

            var model = new ListModelForUserDetail();
            model.userDetails = db.UserInfos.Where(x => x.UserID == userId).ToList();
            model.messages = db.Messages.Where(x => x.SenderUserId == userId && x.MultipleReceiversId == recieverUsersId || x.SenderUserId == recieverUsersId && x.MultipleReceiversId == userId).ToList();

            var searchs = from m in db.MessageThreads select m;
            searchs = searchs.Where(x => x.MessageStarterUserId == 1);


            ViewBag.model = searchs.ToString();

            return PartialView("_getMessage", model);
        }

and this is my main view where i am rendering an action method

 @{Html.RenderAction("_getMessage", new {recieverUsersId=0});}

partial view is written as

@foreach (var item in Model.messages)
{
   if (@item.SenderUserId != ViewBag.loginUserId && @item.FileAttachedURL == "") {
                                <li id="reply" class="bg-color-white"><b class="sticker sticker-right sticker-color-white"></b><p class="text fg-color-blue" id="sendtext @item.MessageId + "> + @item.MessageText + </p><div class="date place-right fg-color-blue" style="margin-top:-10px; font-size:12px;"> + Hour + ':' + minute + ' ' + ampm + ' (' + strDate + ')</div></li>;

                             }
                             else if (@item.SenderUserId != ViewBag.loginUserId && @item.FileAttachedURL != "") {
                               <li id="reply" style="padding:4px 4px 24px 4px;" class="bg-color-white"><b class="sticker sticker-right sticker-color-white fg-color-blue" id="sendtext @item.MessageId + "></b><p class="text fg-color-blue" style="height:auto;">@item.MessageText + </p><br /><img class="fg-color-red" src="@item.FileAttachedURL + " style="height:auto; width:100%; margin-left:auto; margin-right:auto; "/><div class="date place-right fg-color-blue" style="margin-top:0px; font-size:12px;"> + Hour + ':' + minute + ' ' + ampm + ' (' + strDate + ')</div></li>
                             }
                             else if (@item.SenderUserId == ViewBag.loginUserId && @item.FileAttachedURL == "") {
                                <li id="reply" class="bg-color-blue"><b class="sticker sticker-left sticker-color-blue"></b><p class="text fg-color-white"  id="sendtext @item.MessageId + '">@item.MessageText + </p><br/><div class="date place-right fg-color-white" style="margin-top:-10px; font-size:12px;">' + Hour + ':' + minute + ' ' + ampm + ' (' + strDate + ')</div></li>;

                             }
                             else if (item.SenderUserId == (ViewBag.loginUserId) && item.FileAttachedURL != "") {
                                <li id="reply" style="padding:4px 4px 24px 4px;" class="bg-color-blue"><b class="sticker sticker-left sticker-color-blue fg-color-white" id="sendtext @item.MessageId + "></b><p class="text fg-color-white" style="height:auto;"> + @item.MessageText + </p><br /><img class="fg-color-red" src=" + item.FileAttachedURL + " style="height:auto; width:100%; margin-left:auto; margin-right:auto; "/><div class="date place-right fg-color-white" style="margin-top:0px; font-size:12px;">' + Hour + ':' + minute + ' ' + ampm + ' (' + strDate + ')</div></li>
                             }
                             //$('#recieverId').val(item.UserID)

                             //$("#sendtext" + item.MessageId).emoticons();

}

I am not getting my desired result of partial view in main view so what to do now?

9
  • @AndrewBarber i am getting blank webpage Commented Oct 18, 2013 at 18:28
  • I don't see anything particularly wrong here. Are you getting the expected HTML in your success callback? And why are you alerting "Error" in your success callback?
    – Jedediah
    Commented Oct 18, 2013 at 18:29
  • @xdumaine getting error in the view Commented Oct 18, 2013 at 18:34
  • @Jedediah it is just use to cross check Commented Oct 18, 2013 at 18:35
  • can you post your partial view code? Commented Oct 19, 2013 at 4:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.