比如根据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; } } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 微带串馈天线阵列每个阵元宽度计算
- ¥15 关于无人驾驶的航向角
- ¥15 keil的map文件中Image component sizes各项意思
- ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
- ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
- ¥15 划分vlan后,链路不通了?
- ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
- ¥15 Vue3 大型图片数据拖动排序
- ¥15 Centos / PETGEM
- ¥15 划分vlan后不通了