views:

252

answers:

2

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!

+1  A: 

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

Oskar Kjellin
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 ActionResult ShowSingleConverstationWithAnswerForm(string id) { SingleConversationWithAnswerFormViewModel vm = new SingleConversationWithAnswerFormViewModel(id); return PartialView("SingleConverstationWithAnswerForm", vm);}but view opens in new page
niao
+1  A: 

I have a blog post that describes a very similar use case. Source code is included:

http://blog.stevehorn.cc/2009/06/rendering-modal-dialog-with-aspnet-mvc.html

Steve Horn