开发者

another approach to returning some thing to browser in mvc with ajax call instead of using response.write

开发者 https://www.devze.com 2022-12-31 12:09 出处:网络
i have one section in my mvc 2.0 project which doing some processes and after each, return some messages (string) with response.write(). and this messages returned to browser with bad format. i want t

i have one section in my mvc 2.0 project which doing some processes and after each, return some messages (string) with response.write(). and this messages returned to browser with bad format. i want to return messages to one specific HTML div and add each to end of contents of div tag. now how do this?

this event after each procces raised and message returned to browser.

public void OnProgressEvent(System.Object source, CustomEventArgs customEven开发者_运维知识库tArgs)
{
    if (customEventArgs.Level > 5)
    {
        Response.Write(customEventArgs.Message + "<br />");
        Response.Flush();
    }
}


jQuery is your friend here. If you make an ajax call to say an ActionResult, then you can either return a json object or a partial view.

My preference is to return a partial view and then replace the contents of the div with the resultant html.

So;

public ActionResult jQueryTagDelete(string SomeParametersMaybe)
{
    return PartialView("TagList", tags.OrderBy(x => x.keyword1));
}

And you jQuery code;

    function deleteTag(tagName) {
        $.post("/Admin/jQueryTagDelete", { tag: tagName }, function(RETURNED_HTML) {
            document.getElementById("divTags").innerHTML = RETURNED_HTML;
        });
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号