2016-09-13 3 views
0

エラー404が発生しました。これは、特定のリソースが不足していることを意味します。ASP.NET - ActionLinkを使用中にエラーが発生する

私は実際にASP.NET MVCに慣れていません。ルーティングは、私が最も必要なコントローラです。

1 Raportには多くのThrashTypeレコードがあります。彼らは別々のテーブルですが、この時点で問題はありません。

問題は、私がRaportテーブルの正しいビューとレコードを取得することです。

私はビュー内のリンクを置くと私はビュー内のリンクをクリックすると、それは形式{ホスト}/Raport/EditRecords/{string_id}

を持っている(EditRecordsに行くしようとしている)私は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> 
を次のように

 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を理解していません。

EDITは15時37分2016年9月13日@StephenMueckeからの助けを借りて

私は、問題の原因が何であったかを学びました。 彼は私に、より詳細に問題を説明リンク与えた:実際には私のIDは、「:00:00abcde 12.34.56 00」のようにかなった Dots in URL causes 404 with ASP.NET mvc and IIS

を。それをやろうとすると、IEエラー(404)が発生します。

答えは、 "1234560000000abcde"のようにsthにIDを変更することです。これは、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; 

ありがとう:私の場合は

が、これは仕事をしてくれました!

+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で次のルーティングを削除します。

routes.MapRoute(
     "Home", 
     "Edit/{productId}", 
     new { controller = "Home", action = "Edit" }, 
     new { productId = @"\w+" } 
     ); 
関連する問題