Reload MVC2 user control with jQuery

≡放荡痞女 提交于 2019-12-10 23:44:50

问题


I know I've had a ton of questions today, but still trying to get everything under control learning MVC 2 tie right way. Before I get into the question I already tried the solution offered here but I get an 500 internal server error.

So here's what I'm trying to do, I give the user the ability to select from a list of skills (loaded in a ListView user control) or add a new one to the list and select that. The adding new one is completed (using a WCF service & jQuery) but now I'm trying to reload the skills user control.

According to the solution I linked to I added an action to my AccountController

public ActionResult GetSkillControl()
{
    return View("~/Views/Shared/SkillsListView.ascx");
}

I have the control inside a span (so it has a container)

<tr>
    <td style="vertical-align:top;"><label for="SkillsListView" title="Skills">Skills:</label></td>
    <td class="regElements"><span id="SkillListViewContainer"> <% Html.RenderPartial("SkillsListView"); %></span><%= Html.ValidationMessageFor(m => m.Skills, "*")%><br />
    <span id="AddSkillError"></span>
    Add: <input type="text" id="NewSkill" class="inputbox" style="width:75px;" />&nbsp;<input type="button" value="Add" id="AddSkill" name="AddSkill" /></td>
    <td></td>
</tr>    

And in my jQuery ajax call I have

success: function () {
    $('#SkillListViewContainer').load('../AccountController/GetSkillControl');
}

It's when it reaches that point that the JavaScript console in Chrome shows it returns a 500 internal server error. What am I missing here?


回答1:


Based on the standard routes in ASP.NET MVC, try "/Account/GetSkillControl". Anything you use from jQuery's load method must be a valid URL. The route engine is looking or Account and not AccountController. Also by using the leading "/" it will resolving from the root of the site.



来源:https://stackoverflow.com/questions/4503597/reload-mvc2-user-control-with-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!