ASP.NET MVC中Html.BeginForm生成表单问题

LIANNN 2016-03-14 09:59:38
我用Html.BeginForm生成一个表单,为什么生成的表单action后面没有值?点击以后没有反应
@using (Html.BeginForm("AddToCart", "Cart"))
{
@Html.HiddenFor(x => x.ProductID)
@Html.Hidden("returnUrl", Request.Url.PathAndQuery)
<input type="submit" value="+ Add to cart" />
}
...全文
271 9 打赏 收藏 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
LIANNN 2016-03-15
  • 打赏
  • 举报
回复
。。求大神们解答一下阿,困在这里很久了
LIANNN 2016-03-15
  • 打赏
  • 举报
回复
引用 8 楼 x582053774 的回复:
你路由怎么设置的。
。。。路由好像没有设置 要怎么设置??
「已注销」 2016-03-15
  • 打赏
  • 举报
回复
你路由怎么设置的。
LIANNN 2016-03-14
  • 打赏
  • 举报
回复

生成的网页里面action=""不知道是怎么回事
我是照着精通ASP.NET 4.0的书敲的,敲了两遍都有问题。但是我从网上下载那本书的源码和我写的一样,但是
生成的action后面是有东西的
LIANNN 2016-03-14
  • 打赏
  • 举报
回复
引用 3 楼 From_TaiWan 的回复:
没反应?谁知道你是怎么处理接收到的值的
你在action里断点看看有没有值
把提交的代码贴全了,还有action接收的代码

提交的代码:
action接受的代码:
using SportsStore.Domain.Abstract;
using SportsStore.Domain.Entities;
using SportsStore.WebUI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SportsStore.WebUI.Controllers
{
public class CartController : Controller
{
//
// GET: /Cart/
private IProductRepository repository;
public CartController(IProductRepository repo)
{
repository = repo;
}
public RedirectToRouteResult AddToCart(int productId, string returnUrl)
{
Product product = repository.Products.FirstOrDefault(p => p.ProductID == productId);
if (product != null)
{
GetCart().AddItem(product, 1);
}
return RedirectToAction("Index", new { returnUrl });
}
public RedirectToRouteResult RemoveFromCart(int productId, string returnUrl)
{
Product product = repository.Products.FirstOrDefault(p => p.ProductID == productId);
if (product != null)
{
GetCart().RemoveLine(product);
}
return RedirectToAction("Index", new { returnUrl });
}
private Cart GetCart()
{
Cart cart = (Cart)Session["Cart"];
if (cart == null)
{
cart = new Cart();
Session["Cart"] = cart;
}
return cart;
}
public ViewResult Index(string returnUrl)
{
return View(new CartIndexViewModel{
Cart=GetCart(),
ReturnUrl=returnUrl
});
}

}
}

秋的红果实 2016-03-14
  • 打赏
  • 举报
回复
没反应?谁知道你是怎么处理接收到的值的 你在action里断点看看有没有值 把提交的代码贴全了,还有action接收的代码
LIANNN 2016-03-14
  • 打赏
  • 举报
回复
引用 1 楼 From_TaiWan 的回复:
@using (Html.BeginForm("AddToCart", "Cart","Post"))
。并不是这个问题阿 ,我加上了,但是还是不管用阿 ..
秋的红果实 2016-03-14
  • 打赏
  • 举报
回复
@using (Html.BeginForm("AddToCart", "Cart","Post"))

111,128

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧