niao
niao

Reputation: 5070

asp.net-mvc RenderPartial onclick

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!

Upvotes: 0

Views: 2827

Answers (1)

Oskar Kjellin
Oskar Kjellin

Reputation: 21870

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

Upvotes: 1

Related Questions