FineUI 官方论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

本论坛已关闭(禁止注册、发帖和回复)
请移步 三石和他的朋友们

FineUI首页 WebForms - MVC & Core - JavaScript 常见问题 - QQ群 - 十周年征文活动

FineUI(开源版) 下载源代码 - 下载空项目 - 获取ExtJS - 文档 在线示例 - 版本更新 - 捐赠作者 - 教程

升级到 ASP.NET Core 3.1,快、快、快! 全新ASP.NET Core,比WebForms还简单! 欢迎加入【三石和他的朋友们】(基础版下载)

搜索
查看: 6252|回复: 3

【非BUG】Uncaught SyntaxError: Unexpected token < 错误

[复制链接]
发表于 2017-11-18 15:34:06 | 显示全部楼层 |阅读模式
环境 :Vs2017   谷歌浏览器  在【空项目】FineUIMvc.EmptyProject_v4.0.0
中建立如下2个文件


建立view页  QueryIndex.cshtml

  1. @{
  2.     ViewBag.Title = "check";
  3.     var F = @Html.F();
  4. }



  5. @section body {

  6.     @(F.Button()
  7.                         .OnClick(Url.Action("QueryIndex"))
  8.                         .ValidateTarget(Target.Top)
  9.                         .ValidateForms("SimpleForm1")
  10.                         .Type(ButtonType.Submit)
  11.                         .Text("手动请求页面")
  12.                         .ID("btnLogin")
  13.                         )
  14.     @(
  15.    

  16.             F.Grid()
  17.                 .EnableCollapse(true)
  18.                 .Width(850)
  19.                 .Title("事件查询")
  20.                 .ShowHeader(false)
  21.                 .ShowBorder(true)
  22.                 .ID("FaultGrid")
  23.                 .DataIDField("Id")
  24.                 .DataTextField("faultType")
  25.                 .Columns(
  26.                     F.RenderField()
  27.                         .HeaderText("编号")
  28.                         .DataField("Id")
  29.                         .FieldType(FieldType.Int)
  30.                         .Width(100),

  31.                     F.RenderField()
  32.                         .HeaderText("位置")
  33.                         .DataField("StationName")
  34.                         .Width(100),
  35.                     F.RenderField()
  36.                         .HeaderText("类型")
  37.                         .DataField("faultType")
  38.                         .Width(100),
  39.                     F.RenderField()
  40.                         .HeaderText("发生时间")
  41.                         .DataField("faultBeginTime")
  42.                         .FieldType(FieldType.String)
  43.                         .Width(100),
  44.                     F.RenderField()
  45.                         .HeaderText("复位时间")
  46.                         .DataField("faultEndTime")
  47.                         .FieldType(FieldType.String)
  48.                         .Width(100),

  49.                     F.RenderField()
  50.                         .HeaderText("描述")
  51.                         .DataField("faultMemo")
  52.                         .Width(200)


  53.                 )
  54.                 .DataSource(ViewBag.tab)

  55.         )

  56. }

  57. }
复制代码
建立控制   QueryController.cs

  1. using FineUIMvc;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Mvc;


  7. namespace TestWeb.Controllers
  8. {
  9.     public class QueryController : BaseController
  10.     {
  11.         // GET: Query

  12.         public ActionResult QueryIndex()
  13.         {

  14.             test[] testinst = new test[1];
  15.             test testi = new test();
  16.             testi.Id = 4;
  17.             testi.StationName = "ccccc";
  18.             testi.faultType = "c";
  19.             testi.faultBeginTime = "dddccc";
  20.             testi.faultEndTime = "234";
  21.             testi.faultMemo = "3d";
  22.             testinst[0] = testi;
  23.               ViewBag.tab = testinst;
  24.              return View();

  25.         }


  26.         public  class test
  27.             {
  28.             public int Id { get; set; }
  29.             public string StationName { get; set; }
  30.             public string faultType { get; set; }
  31.             public string faultBeginTime { get; set; }
  32.             public  string faultEndTime { get; set; }
  33.             public  string faultMemo { get; set; }
  34.             }



  35.          
  36.         public ActionResult QueryFaultButtonClick( )
  37.         {
  38.             try {


  39.                 test[] testinst = new test[1];
  40.                 test testi = new test();
  41.                 testi.Id = 4;
  42.                 testi.StationName = "ddddddd";
  43.                 testi.faultType = "c";
  44.                 testi.faultBeginTime = "dddccc";
  45.                 testi.faultEndTime = "234";
  46.                 testi.faultMemo = "3d";

  47.                 testinst[0] = testi;
  48.                 //     ViewBag.tab = testinst;

  49.                 return View();

  50.             }
  51.             catch (Exception ex)
  52.             {

  53.                 ShowNotify("查询失败" + ex.Message);
  54.     }
  55.             return UIHelper.Result();
  56.         }
  57.     }
  58. }
复制代码




运行后,输入地址: http://localhost:49547/Query/QueryIndex

得到结果


这时候 按 F12 打开 浏览器调试

点   手动刷新页面   就出问题了,




这个问题困扰了2天了 求解决 ,谢谢



另外用 实例源码中的  Areas\FormLayout\Views\LayoutContactUs\Index.cshtml这个文件做测试

将这个文件的 发送 按钮 加一句 如下 (红色的)

                   F.Button()
                        .ID("Button1")
                        .Text("发送")
                        .IconFont(IconFont._Send)
                        .ValidateForms("Form1")
                        .OnClick(Url.Action("Index"))


运行后 也同样报错


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
发表于 2017-11-20 10:16:37 | 显示全部楼层
这个不是BUG。

在 FormLayout/LayoutContactUs/Index 示例中:
  1. .Toolbars(
  2.             F.Toolbar()
  3.                 .ID("Toolbar1")
  4.                 .ToolbarAlign(ToolbarAlign.Right)
  5.                 .Position(ToolbarPosition.Bottom)
  6.                 .Items(
  7.                     F.Button()
  8.                         .ID("Button1")
  9.                         .Text("发送")
  10.                         .IconFont(IconFont._Send)
  11.                         .ValidateForms("Form1") .OnClick(Url.Action("Index"))
  12.                 )
  13.         )
复制代码
添加 OnClick 后,可以看下对应的控制器方法是:
  1. public class LayoutContactUsController : FineUIMvc.Examples.Controllers.BaseController
  2. {
  3.         // GET: FormLayout/LayoutContactUs
  4.         public ActionResult Index()
  5.         {
  6.                 return View();
  7.         }

  8. }
复制代码


然后,在用户点击提交按钮时,返回的内容是HTML格式,这显然不是 FineUIMvc 所期望的结果:



=======
FineUIMvc中控件事件对应的控制器方法一定要返回:UIHelper.Result()

例如:
  1. [HttpPost]
  2. [ValidateAntiForgeryToken]
  3. public ActionResult btnHello_Click()
  4. {
  5.         Alert.Show("你好 FineUIMvc!", MessageBoxIcon.Warning);

  6.         return UIHelper.Result();
  7. }
复制代码



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
 楼主| 发表于 2017-11-21 12:23:03 | 显示全部楼层
本帖最后由 ftmouse 于 2017-11-21 12:25 编辑
sanshi 发表于 2017-11-20 10:16
这个不是BUG。

在 FormLayout/LayoutContactUs/Index 示例中:
谢谢您的回复!
使我我进一步的理解了这个非常棒的类库


我的本意是 当按查询后 返回 一堆数据,并且要填到表格里,
看了直接 返回view 是不行的
必须改变表格的source
另外 我不理解的是,
为什么 在控制器里 改变表格的source 的时候 必须 带 列参数 fields

  1. public ActionResult QueryFaultButtonClick(FormCollection values, string fields)
  2. {
  3.                      JArray FaultGridfields = JArray.Parse(fields);
  4.                 .................
  5.                 UIHelper.Grid("FaultGrid").DataSource(fault_array, FaultGridfields);
  6. }
复制代码
发表于 2017-11-21 15:11:41 | 显示全部楼层
ftmouse 发表于 2017-11-21 12:23
谢谢您的回复!
使我我进一步的理解了这个非常棒的类库

MVC在回发时不会保持状态,所以后台并不知道用了到了数据源中哪些列,fields正好是对此进行过滤
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|FineUI 官方论坛 ( 皖ICP备2021006167号-1 )

GMT+8, 2024-3-29 21:32 , Processed in 0.048699 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表