mvc 5 ajax:httpError 400.0错误请求

时间:2015-12-18 12:20:42

标签: ajax asp.net-mvc-5 partial-views

遇到ajax的问题​​我正在使用vs 2015 mvc 5。 以下是具有1对多关系的两个模型类。 我正面临一些问题。

  1. 该视图不会产生预期的链接,即相反 〜/ Global / Cities / Details / 1 仅产生〜/ Global / Cities / Details /
  2. 当我通过 httperror 400.0 Bade Request
  3. 在浏览器中手动修复它时
  4. 当我从ajax选项中删除 Url 属性时,部分视图会在新标签页窗口中打开
  5. 
    
    namespace WebApplication1.Areas.Global.Models
        {
            public class Organization
            {
                public virtual int OrganizationId { get; set; }
                public virtual int CityId { get; set; }
                public virtual string Name { get; set; }
                public virtual City city { get; set; }
    
            }
    
    
            public class City
            {
                public virtual int CityId { get; set; }
                public virtual string Name { get; set; }
                public virtual ICollection<Organization> Organization { get;set; }
    
            }
        }
    &#13;
    &#13;
    &#13;

    这是部分视图控制器..

    &#13;
    &#13;
    public ActionResult Details(int? id)
            {
                if (id == null)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }
                City city = db.Cities.Find(id);
                if (city == null)
                {
                    return HttpNotFound();
                }
                return PartialView(city);
            }
    &#13;
    &#13;
    &#13;

    &#13;
    &#13;
    <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DropDownList("Organizations",new SelectList(item.Organization, "OrganizationId","Name"))
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id=item.CityId }) |
                @Ajax.ActionLink("Details", "Details",item.CityId,
                new AjaxOptions
                {
                    UpdateTargetId = "detail",
                    Url = Url.Action("Details",item.CityId)
                }, new { id=item.CityId }) |
                @Html.ActionLink("Delete", "Delete", new { id=item.CityId })
            </td>
    </tr>
    &#13;
    &#13;
    &#13;

    我还在布局页面中渲染 jqueryval 包... 我的代码有任何问题请帮助....

0 个答案:

没有答案