我的HttpGet函数导致页面错误

时间:2017-08-14 08:27:22

标签: c# asp.net sql-server

我目前正在开发一个C#ASP.NET项目,但我是html / css的新手。我的问题是:

在页面上:"http://localhost:27253/Default/TcpDump/",我有一个激活“SimonTest”功能的按钮:当我点击它时,它会将我带到页面上:"http://localhost:27253/Default/TcpDump/SimonTest/2/1"。但是程序应该做的是:(1)执行“SimonTest”功能,(2)将我带回"http://localhost:27253/Default/TcpDump/SimonTest/2/1"。有什么想法吗?

注意:当我手动返回第一页时,该按钮会尝试将我带到"http://localhost:27253/Default/TcpDump/TcpDump/SimonTest/2/1"

这是我的HttpGet功能代码

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");
        }
    }
}

TcpDumpIndex.cshtml包含:

@{
    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>

我真的不知道这意味着什么,一个人只是告诉我把这一行放在我的代码中以刷新我的页面。

如果这有帮助,这里是包含按钮的文件的代码:

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
        }
    }
}

1 个答案:

答案 0 :(得分:0)

只是为了澄清您的操作方法SimonTest将视图返回为

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

不应该是

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

除非你这样命名?您也可以从RouteConfig发布代码吗?您是否在控制器级别添加了任何路由?

请编辑你的帖子,这样我就能更好地理解你做错了什么。