2017-08-14 2 views
0

Ich arbeite derzeit an einem C# ASP.NET-Projekt, aber ich bin ein ziemlich Neuling in HTML/CSS. Meine Frage ist:Meine HttpGet-Funktion führt zu der falschen Seite

Auf der Seite: "http://localhost:27253/Default/TcpDump/" habe ich eine Schaltfläche, die die Funktion "SimonTest" aktivieren: Wenn ich darauf klicke, bringt es mich auf die Seite: "http://localhost:27253/Default/TcpDump/SimonTest/2/1". Aber was das Programm tun soll ist: (1) führe die Funktion "SimonTest" aus und (2) bringt mich zurück zu "http://localhost:27253/Default/TcpDump/SimonTest/2/1". Irgendeine Idee?

Hinweis: Wenn ich manuell auf die erste Seite zurückzukehren, versucht die Schaltfläche mich zu bringen "http://localhost:27253/Default/TcpDump/TcpDump/SimonTest/2/1"

Hier ist meine HttpGet Funktionscode

namespace Serene5.Default.Pages 
{ 
    using Serenity; 
    using Serenity.Data; 
    using Serenity.Web; 
    using System.Web.Mvc; 
    using System.Data.SqlClient; 
    using System.Data; 

    [RoutePrefix("Default/TcpDump"), Route("{action=index}")] 
    [PageAuthorize(typeof(Entities.TcpDumpRow))] 
    public class TcpDumpController : Controller 
    { 
     public ActionResult Index() 
     { 
      return View("~/Modules/Default/TcpDump/TcpDumpIndex.cshtml"); 
     } 

     [HttpGet] 
     [Route("SimonTest/{id=0}/{obj=0}")] 
     public ActionResult SimonTest(int id, int obj) 
     { 
      string[] listColumns = new string[] { "TimeStp", "IdTransmission", "IdSource", "IdDestination", "PortSource", "PortDestination", "ToTheRight", "ToTheLeft" }; 
      SqlConnection myConn = new SqlConnection(@"Server=(LocalDb)\MSSqlLocalDB;Integrated security=SSPI;database=Serene5_Default_v1"); 
      string listDb = string.Format("SELECT * FROM [Serene5_Default_v1].[tcpdump].[TCPDump] WHERE IdTransmission = {0}", obj); 
      SqlCommand myCommand = new SqlCommand(listDb, myConn); 
      string command = "INSERT INTO Serene5_Default_v1.tcpdump."; 
      if (id == 1) 
      { 
       command += "Errors ("; 
      } 
      else 
      { 
       command += "Regeln ("; 
      } 
      string temp = "("; 
      myConn.Open(); 
      SqlDataReader reader = myCommand.ExecuteReader(); 
      while (reader.Read()) 
      { 
       for (int i = 0; i < reader.FieldCount - 1; i++) 
       { 
        command += reader[i] + ","; 
        temp += listColumns[i] + ","; 


       } 
       command += reader[reader.FieldCount - 1]; 
       temp += listColumns[reader.FieldCount - 1]; 
      } 

      reader.Close(); 
      command += ") INTO " + temp + ");"; 
      System.Diagnostics.Debug.WriteLine(command); 
      SqlCommand myCommand2 = new SqlCommand(listDb, myConn); 

      myCommand2.ExecuteNonQuery(); 
      System.Diagnostics.Debug.WriteLine("Commande exécutée"); 
      myCommand2.Dispose(); 




      myConn.Close(); 
      return View("~/Modules/Default/TcpDump/SimonTest.cshtml"); 
     } 
    } 
} 

Die TcpDumpIndex.cshtml enthält:

@{ 
    ViewData["Title"] = Serenity.LocalText.Get("Db.Default.TcpDump.EntityPlural"); 
} 

<div id="GridDiv"></div> 

<script type="text/javascript"> 
    jQuery(function() { 
     new Serene5.Default.TcpDumpGrid($('#GridDiv'), {}).init(); 

     Q.initFullHeightGridPage($('#GridDiv')); 
    }); 
</script> 

Ich bin mir nicht wirklich bewusst, was es bedeutet, ein Typ hat mir nur gesagt, dass ich diese Zeile in meinen Code schreiben soll, um meine Seite zu aktualisieren.

Wenn das helfen kann, hier ist der Code der Datei auf die Schaltfläche enthält:

namespace Serene5.Default { 

    @Serenity.Decorators.registerClass() 
    export class TcpDumpGrid extends Serenity.EntityGrid<TcpDumpRow, any> { 
     protected getColumnsKey() { return 'Default.TcpDump'; } 
     protected getDialogType() { return TcpDumpDialog; } 
     protected getIdProperty() { return TcpDumpRow.idProperty; } 
     protected getLocalTextPrefix() { return TcpDumpRow.localTextPrefix; } 
     protected getService() { return TcpDumpService.baseUrl; } 

     constructor(container: JQuery) { 
      super(container); 
     } 
     protected getColumns(): Slick.Column[] { 

      var columns = super.getColumns(); 

      var fld = TcpDumpRow.Fields; 
      var time = $.now(); 

      columns.unshift(
       { 
        field: "Objekte", 
        name: "Objekte", 
        format: ctx => { 
         var item = ctx.item; //data for that row 
         return "<a class='modal-link' href='TcpDump/SimonTest/1/" + item.IdTransmission + "' title='Gewöhnlich'><i class='fa fa-check-circle-o' aria-hidden='true'></i>"; 
        }, 
        width: 120, 
        minWidth: 120, 
        maxWidth: 150 
       }); 

      columns.unshift(
       { 
        field: "Objekte", 
        name: "Objekte", 
        format: ctx => { 
         var item = ctx.item; //data for that row 
         return "<a class='modal-link' href='TcpDump/SimonTest/2/" + item.IdTransmission + "' title='Seltsam'><i class='fa fa-times-circle-o' aria-hidden='true'></i>"; 
        }, 
        width: 120, 
        minWidth: 120, 
        maxWidth: 150 
       }); 
      return columns 
     } 
    } 
} 

Antwort

0

Nur zur Klarstellung Ihrer Aktionsmethode SimonTest Rückkehr Ansicht als

return View("~/Modules/Default/TcpDump/TcpDumpIndex.cshtml"); 

Sollte es nicht

sein
return View("~/Modules/Default/TcpDump/SimonTest.cshtml"); 

Sofern Sie es nicht so benannt haben? Kannst du auch Code von RouteConfig eingeben und hast du irgendeine Route auf Controller-Ebene hinzugefügt?

Bitte bearbeiten Sie Ihren Beitrag, damit ich besser verstehen kann, was Sie falsch machen.

+0

Ich erklärte den Inhalt von TcpDumpIndex ^^! Ich habe keine Dateien namens "SimonTest.cshtml", ich verwende einen Controller, meine Funktion befindet sich in einer Datei namens "TcpDumpPage.cs" –

Verwandte Themen