【问题标题】:Update the Page without refresh it更新页面而不刷新它
【发布时间】:2014-06-18 09:24:08
【问题描述】:

目标:
当您单击行 (1) 时,将显示新数据 (3.),而不会更新/刷新整个网页。

问题:
1.
我需要建议,但我不知道在哪里可以找到显示图片编号 2 的功能以及如何在不更新/刷新整个网页的情况下显示数据和新对象 (3.)?

还有

2
如何创建一个图标来显示加载图片?

信息:
- 该页面基于 ASP.mvc 和 C#

【问题讨论】:

  • 可以使用ajax调用。
  • 1 号还是 2 号?你有它的教程吗?

标签: c# javascript asp.net-mvc


【解决方案1】:

使用 jquery 或 MVC ajax 助手的 ajax 功能。

你可以找到jquery ajaxhere

和 MVC ajax 助手库here

here

您可以对服务器的 web 服务进行 ajax 调用,它可以返回一种众所周知的 web 格式(例如 json 或 XML)。当 web 服务调用返回时,您可以使用 javascript(dom 操作)或使用 MVC 助手“注入”您的 html 页面中的数据。

这里有一个可以帮助.. http://www.asp.net/mvc/tutorials/older-versions/javascript/creating-a-mvc-3-application-with-razor-and-unobtrusive-javascript

【讨论】:

  • 谢谢你们的帮助!
【解决方案2】:

您可以使用 jquery ajax 来调用异步操作方法(函数)。数据以 Json 的形式返回。您可以编写代码来反序列化数据并使用 jquery 显示它。 创建一个 Action 方法,它将 JsonResult 作为 viewresult 返回为

public JsonResult GetJsonData()
{
 return Json(new
                    { testDataResult =TestDataResultObj.Data
                       JsonRequestBehavior
                    }, JsonRequestBehavior.AllowGet);
}

并编写以下 jquery 代码:- if (GetDataAsyc()) {

                        $.ajax({
                            type: "GET",
                            data: { testData: testDataResult },
                            url: url,// url of action method to be called asynch
                            dataType: "json",
                            cache: false,
                            traditional: true,
                            contentType: "application/json",
                            success: function (data) {

                                   // on success assign  testDataResult to messages //line
                                    $("#MessagesLines").html(testDataResult .Html);

                                }
                            },
                            error: function () {
                                //Display error message
                                $("ErrorMsg").html("There was error whey trying to process your request") 
                            }
                        });
                    } 

【讨论】:

  • 你有教程中的具体例子吗?
  • @FullMetalGame 请检查我的回答。
  • 谢谢你们的帮助!
【解决方案3】:

使用ajax+PartialViews更新部分页面部分

【讨论】:

  • 谢谢你们的帮助!
猜你喜欢
  • 1970-01-01
  • 2020-07-28
  • 2011-12-22
  • 1970-01-01
  • 2016-06-10
  • 2019-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多