0

I'm trying to render a particular section/div click a particular link or button. Suppose link/button is in the A.cshtml page , and b.cshtml is a partial view that I want to load in A.cshtml page within a particular section/div. I tried Ajax.ActionLink but can't do. Any help or suggestions?

3 Answers 3

1

I tried ajaxactionlink but cant do

That's really not the way to ask a question here. Cant do is not a precise problem description. Next time when you ask a question on SO show what you have tried.

This being said, let me provide you with an example:

@Ajax.ActionLink("click me", "SomeAction", new AjaxOptions {
    UpdateTargetId = "result"
})
<div id="result"></div>

and then you will have an action which will render this partial view:

public ActionResult SomeAction()
{
    return PartialView("_NameOfYourPartial");
}

Finally make sure that you have referenced the jquery.unobtrusive-ajax.js script to your page which uses the HTML5 data-* attributes emitted by the Ajax.ActionLink helper to hijack the click event and send an AJAX request instead of the normal request:

<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
Sign up to request clarification or add additional context in comments.

Comments

0

The controller can return a partial view as action result:

public ActionResult Details()
{
    var model = // your model
    var viewName = // your partial view name
    return PartialView(viewName, model);
}

Comments

0

Ajax.ActionLink should do it, may be you missed somwthing. Check this post it may give you the answer

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.