比如根据EF生成了controller,我在之前的页面抓了几个值来一个create页面。我想让用户不必要点击那个“Submit”按钮,后台直接上传后这些值后跳转到下一个页面。
可以写一个例子给你,但是你得把问题描述清楚,你说页面抓了几个值来一个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;
}
}
}