asp.net-mvc RenderPartial onclick

发布于 2024-08-30 01:42:26 字数 1013 浏览 11 评论 0原文

问候, 我有一个 ASP.NET MVC 应用程序。我有一些与客户姓名相对应的链接。当用户单击此链接时,我想显示单击的客户端的信息以及另外一个文本区域,用户可以在其中编写有关所选客户端的一些文本(评论)。我怎样才能实现它?

编辑 我做了类似的事情:

<%=Html.ActionLink(operatorWhoAnswered.Operator.FirstName, "ShowSingleConverstationWithAnswerForm", "MyMessages", new { id = operatorWhoAnswered.Operator.ROWGUID }, new AjaxOptions() { UpdateTargetId = "ss" }) %> 

我的控制器操作如下所示:

public PartialViewResult ShowSingleConverstationWithAnswerForm(string id)
        {
            SingleConversationWithAnswerFormViewModel vm = new SingleConversationWithAnswerFormViewModel();
            PartialViewResult viewResult = new PartialViewResult();
            viewResult.ViewName = "SingleConverstationWithAnswerForm";
            viewResult.ViewData = new ViewDataDictionary(vm);
            return viewResult;
        }

但视图在新页面中打开,而不是 id="ss"

EDIT2 的 div 找到解决方案了!我不知道为什么我使用了 Html.ActionLink。 Ajax.ActionLink 工作正常!

Greetings,
I have an asp.net mvc application. I have some links that corresponds to clients names. When user clicks on this link I would like to show an information of clicked client and additionally a textarea where user shall be able to write some text (comment) about selected client. How can I achieve it?

EDIT
I've made something like:

<%=Html.ActionLink(operatorWhoAnswered.Operator.FirstName, "ShowSingleConverstationWithAnswerForm", "MyMessages", new { id = operatorWhoAnswered.Operator.ROWGUID }, new AjaxOptions() { UpdateTargetId = "ss" }) %> 

and my controller action looks as follows:

public PartialViewResult ShowSingleConverstationWithAnswerForm(string id)
        {
            SingleConversationWithAnswerFormViewModel vm = new SingleConversationWithAnswerFormViewModel();
            PartialViewResult viewResult = new PartialViewResult();
            viewResult.ViewName = "SingleConverstationWithAnswerForm";
            viewResult.ViewData = new ViewDataDictionary(vm);
            return viewResult;
        }

but view opens in a new page, instead of div with id="ss"

EDIT2
Solution found! I don't know why I have used Html.ActionLink. Ajax.ActionLink works fine!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寒冷纷飞旳雪 2024-09-06 01:42:26

尝试这样的事情:

创建一个当用户单击时应该呈现的 div。名字就像blabla。然后你的链接在哪里你有类似的东西

 <%=Ajax.ActionLink("Click here", "Action", "Controller", new { id = "some test data passed in"}, new AjaxOptions() { UpdateTargetId = "blabla" })%>

并让该操作返回你的视图

Try something like this:

Create a div that should be rendered when the user clicks. Name is something lika blabla. Then where your link is you have something like

 <%=Ajax.ActionLink("Click here", "Action", "Controller", new { id = "some test data passed in"}, new AjaxOptions() { UpdateTargetId = "blabla" })%>

And let that action return your view

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文