2016-09-13 3 views
0

404 오류가 발생하여 특정 리소스가 부족하다는 것을 알았습니다.ASP.NET - ActionLink 사용 중 오류가 발생했습니다.

저는 ASP.NET MVC에서 실제로 경험이 없으며 라우팅은 내가 가장 필요로하는 곳입니다. 이것은 내가 필요한 컨트롤러 + 동작을 가지고 있기 때문에 예측할 수없는 오류입니다.

1 Raport에는 많은 ThrashType 레코드가 있습니다. 그것들은 별개의 테이블입니다. 그러나이 시점에서는 중요하지 않습니다.

문제는 내가 Raport 테이블의 올바른보기와 레코드를 얻는다는 것입니다.

내가보기에 링크를 가져 가면 그 것이다 형식 내가보기에있는 링크를 클릭하면 (EditRecords로 이동하려고)

{호스트}/Raport/EditRecords/{string_id} 내가 얻을 404 오류가 혼란스러운 atm.

컨트롤러 EditRaport :

public ActionResult EditRaport() 
    { 
     var query = from dbs in db.Raport 
        select dbs; 

     return View(query as IEnumerable<Raport>); 
    } 

컨트롤러 EditRecords : EditRaport위한

 public ActionResult EditRecords(string id) 
    { 
     var query = from dbs in db.ThrashType 
        where dbs.raport_id == id 
        select dbs; 

     return View(query as IEnumerable<ThrashType>); 
    } 

전망 :

@model IEnumerable<WebApplication1.Klasy_Raport.Raport> 

@{ 
    ViewBag.Title = "EditRaport"; 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
} 

<h2>Edit Raport</h2> 


<table class="table"> 
    <tr> 
     <th> 
      @Html.DisplayNameFor(model => model.UserFrontInfo.userName) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.creation_time) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.last_modyfication) 
     </th> 
     <th></th> 
    </tr> 

@foreach (var item in Model) { 
    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.UserFrontInfo.userName) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.creation_time) 
     </td>  
     <td> 
      @Html.DisplayFor(modelItem => item.last_modyfication) 
     </td> 
     <td> 
      @Html.ActionLink("Edit", "EditRecords", new { id=item.raport_id }) 

     </td> 
    </tr> 
} 

</table> 
,369을 다음

 public static void RegisterRoutes(RouteCollection routes) 
     {     
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

      routes.MapRoute(
       name: "Default", 
       url: "{controller}/{action}/{id}", 
       defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
      ); 


      routes.MapRoute(
      "Home", 
      "Edit/{productId}", 
      new { controller = "Home", action = "Edit" }, 
      new { productId = @"\w+" } 
      ); 
     } 

코드는

오류의 위치에 대한 단서를 제공해 주시겠습니까? 나는이 경우에 404를 정말로 이해하지 못한다.

편집 15시 37분 2016년 9월 13일 @StephenMuecke의 도움으로

나는 문제의 원인이 무엇인지 배웠습니다. ": 00 : 00abcde 12.34.56 00" 는 Dots in URL causes 404 with ASP.NET mvc and IIS

사실 내 ID는 STH 좋아했다 : 그는 나에게 더 자세히 문제를 설명하는 링크를했다. 당신이 그것을하려고하면 IE 오류 (404)가 발생합니다.

대답은 ID가 "1234560000000abcde"와 같이 sth로 변경되어 IE가 정상적으로 처리되도록합니다.

//remove dots and colons from string 
    var datePart = DateTime.Today.ToString().Replace(".", "").Replace(":",""); 

    //giving string properties and assigning for alias 
    var namePart = User.Identity.Name.ToString(); 

    //removing @blablabl.ab - 12 signs, 13 is for the sake of correct  indexing 
    var nameShort = namePart.Remove((namePart.Length)-13, 12); 

    //final ID concatenation 
    newRaport.raport_id = datePart + nameShort; 

감사 : 내 경우

이 일을했다!

routes.MapRoute(
     "Home", 
     "Edit/{productId}", 
     new { controller = "Home", action = "Edit" }, 
     new { productId = @"\w+" } 
     ); 
+0

당신은'EditRecords'에 대한보기가 있습니까 : –

+0

EditRecords 액션 - Raport 컨트롤러의 일부입니까? – Andrei

+0

컨트롤러 EditRecordsController에서 EditRecords 액션이 있거나 컨트롤러 이름이 무엇입니까? – Hypnobrew

답변

0
 public static void RegisterRoutes(RouteCollection routes) 
    {     
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     routes.MapRoute(
      name: "Default", 
      url: "{controller}/{action}/{id}", 
      defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
     ); 


     routes.MapRoute(
     "Home", 
     "Edit/{productId}", 
     new { controller = "Home", action = "Edit" }, 
     new { productId = @"\w+" } 
     ); 
    } 

는 RegisterRoutes에 다음과 라우팅을 제거?
관련 문제