Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用asp.net mvc对话框的jquery_Jquery_Asp.net Mvc - Fatal编程技术网

使用asp.net mvc对话框的jquery

使用asp.net mvc对话框的jquery,jquery,asp.net-mvc,Jquery,Asp.net Mvc,我有一个html链接,我想弹出一个对话框,其中包含用户名和复选框列表。然后,用户可以选择一个或多个复选框并单击OK,该信息将被传递回主GUI。这可能是使用jquery实现的,还是我应该使用另一种技术?没有jquery是实现这一点的完美工具 你所需要做的就是在你的控制器中返回你的ActionResult,返回你的数据[或者更好的部分视图],并在页面上显示它 如果你想要示例代码,请告诉我,我会发布一些 但本质上您需要执行$.post(“/controller/action”{arg1:val1,ar

我有一个html链接,我想弹出一个对话框,其中包含用户名和复选框列表。然后,用户可以选择一个或多个复选框并单击OK,该信息将被传递回主GUI。这可能是使用jquery实现的,还是我应该使用另一种技术?

没有jquery是实现这一点的完美工具

你所需要做的就是在你的控制器中返回你的ActionResult,返回你的数据[或者更好的部分视图],并在页面上显示它

如果你想要示例代码,请告诉我,我会发布一些

但本质上您需要执行
$.post(“/controller/action”{arg1:val1,arg2:val2},函数(retHtml){code to show data})

在你的控制器中,类似这样的东西

public ActionResult action(string arg1, string arg2)
{
  //Do guff
  return PartialView("MyPartialView", FormViewModel);
}
如果您需要解释样品,请在评论中告诉我

编辑:

我给出的代码实际上是相当完整的,但是让我们稍微充实一下,让它变得简单一些。有更好的方法可以做到这一点,但如果您是jQuery新手,这很容易理解

让我们从视图开始

您可以这样说一个按钮:

<input id="submitBtn" name="submitBtn" type="submit" onclick="postComment(<%=Model.Id %>); return false;" value="Submit" />
上面的代码所做的只是从一个字段抓取注释文本,然后将jQueryAddComment的操作发回我的控制器,并传入一些变量

在我的控制器中,我现在有

public ActionResult jQueryAddComment(string commentText, int id)
{
  //code here to add the new comment to the database.

  //more code to get the new list of comments from the database and into a model

  //code to return a partial view back to the view itself
  return PartialView("CommentList", fvm);

}
上述jQuery代码中的回调调用一个普通Javascript函数来获取返回的HTML并将其显示在页面上

在您的例子中,您将显示一个包含HTML的Div,并向其提供单击事件,以便用户可以与之交互

这更清楚了吗

public ActionResult jQueryAddComment(string commentText, int id)
{
  //code here to add the new comment to the database.

  //more code to get the new list of comments from the database and into a model

  //code to return a partial view back to the view itself
  return PartialView("CommentList", fvm);

}