比如根据EF生成了controller,我在之前的页面抓了几个值来一个create页面。我想让用户不必要点击那个“Submit”按钮,后台直接上传后这些值后跳转到下一个页面。
1条回答
- threenewbee 2019-04-23 17:59关注
代码下载:https://download.csdn.net/download/caozhy/11158474
可以写一个例子给你,但是你得把问题描述清楚,你说页面抓了几个值来一个create页面,那么服务器已经有这些了,只要用tempdata/viewbag传就可以了
如果是用户输入,你说自动提交,那么怎么让用户输入,怎么判断用户完成了输入,还是需要一个用户确认的过程。<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<Q758222.Models.ProductModel>" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Index </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Index</h2> <%: Html.ActionLink("创建", "Create", "Products") %> <hr /> <script language="javascript"> function autopost(name) { $.post("products/create", "name=" + name, function (data, status) { alert(data); }); } </script> <a href="javascript:autopost('asdfaaa')">自动创建</a> </asp:Content>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Q758222.Models; namespace Q758222.Models { public class ProductsController : Controller { // // GET: /Products/ public ActionResult Index() { return View(); } // // GET: /Products/Create public ActionResult Create() { return View(); } // // POST: /Products/Create [HttpPost] public string Create(FormCollection fc) { var model = new ProductModel(); UpdateModel(model); return "你已经成功创建: " + model.Name; } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥50 buildozer打包kivy app失败
- ¥30 在vs2022里运行python代码
- ¥15 不同尺寸货物如何寻找合适的包装箱型谱
- ¥15 求解 yolo算法问题
- ¥15 虚拟机打包apk出现错误
- ¥15 用visual studi code完成html页面
- ¥15 聚类分析或者python进行数据分析
- ¥15 三菱伺服电机按启动按钮有使能但不动作
- ¥15 js,页面2返回页面1时定位进入的设备
- ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复