0

i worked on a partial reload page via Ajax. This is what i have:

Controller:

public class EmailController : Controller
    {
        //
        // GET: /Email/
        [Authorize]
        public ActionResult Index(string id)
        {
            //.. Some Code here to get my Email List
            return View(emails);
        }
        [Authorize]
        public PartialViewResult EmailPartial(string id = "1,2")
        {
            //.. Some Code here to get my Email List with the new filter
            return PartialViewResult(emails);
        }
    }

Main View:

@model IEnumerable<namespace.Emailgesendetview>

@{
    ViewBag.Title = "Index";
    AjaxOptions ajaxOpts = new AjaxOptions
    {
        UpdateTargetId = "emailBody"
    };
    Layout = "~/Views/Shared/_Default.cshtml";
}
    // .... uninteresting html code
        <div id="emailBody">
            @Html.Action("EmailPartial", new { selectedRole = Model })
        </div>
    // .... uninteresting html code
    // Here comes my action link:
        <li>        
                    @Ajax.ActionLink("martin",
                            "EmailPartial",
                            "Email",
                             new { id = "3"},
                             new AjaxOptions()
                             {
                                 HttpMethod = "GET",
                                 AllowCache = false,
                                 InsertionMode = InsertionMode.Replace,
                                 UpdateTargetId = "emailBody"
                             })
        </li>

Partial View:

@model IEnumerable<namespace.Emailgesendetview>   
<div class="mail-body">
    <ul class="mail-list">
        @{
            foreach (var userMail in Model)
            {
                //... Code vor showing the models
            }
        }
    </ul>
</div>

If i click on the link now, he starts the function: EmailPartial, but he didn't add (or replace i tryed both) the content. He Opens the EmailPartial view alone?!

In this post: How to render partial view in MVC5 via ajax call to a controller and return HTML the Partial function is not a PartialViewResult it's a ActionResult, but i already tryd that.

Would be great i you could show me my error or misstake.

Thanks a lot and have a nice day :)

Community
  • 1
  • 1
TheRealLife
  • 305
  • 2
  • 19
  • Why are you assigning value in function parameter ? EmailPartial(string id = "1,2") – Basanta Matia Mar 31 '17 at 10:13
  • 2
    Sounds like you did a standard get, you might be missing jquery.unobtrusive.js in your scripts. That is what wires up the Ajax functions in Mvc – Slicksim Mar 31 '17 at 10:15
  • to be sure there is a value for my list, if the page loads without a ajax call i want to get my mails with index 1 and 2 :) – TheRealLife Mar 31 '17 at 10:15
  • 2
    Because you have not included `jquery-unobtrusive-ajax.js` in your view or layout so its making a normal redirect. –  Mar 31 '17 at 10:30

1 Answers1

0

Because you have not included jquery-unobtrusive-ajax.js in your view or layout so its making a normal redirect. – Stephen Muecke Mar 31 at 10:30

TheRealLife
  • 305
  • 2
  • 19