我想发布一些关于ASP.Net MVC的问题。我不熟悉web开发,但我被分配到一个项目的web部分。我们正在执行以下操作:首先,我们为person数据创建get & set属性:
public class Person
{
public int personID {get;set;}
public string personName {get;set;}
public string nric {get;set;}
}
登录后,我们将数据放在一个类Person对象中,并像这样使用RedirectToAction:
return RedirectToAction(&
我目前正在使用新的ASP.NET MVC2框架开发一个应用程序。最初,我是在ASP.NET MVC1中开始编写此应用程序的,现在基本上只是将其更新为MVC2。
这里我的问题是,我并不真正理解FormCollection对象与旧类型对象的概念。
这是我当前的代码:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(FormCollection collection)
{
try
{
Member member = new Member();
member.FirstName = col
我是Ruby框架的新手,刚从ASP.NET on Rails 3迁移过来,它是ActiveRecord。请帮我理解一下dalAccess在MVC中的位置。
[HttpGet]
public ActionResult copyCampaign(int Id)
{
DALAccess dalaccess = new DALAccess();
//string newid = dalaccess.CopyOffer(Id);
string newid = dalaccess.CopyOfferByCampaignId(Id);
我阅读了关于如何在rails中对路由进行前缀的文章。我希望能够用asp.net mvc做同样的事情。
因此,我希望能够定义这样的路线:
/photographers/1/photos/2 //photo 2 of photographer with id 1
/photographers/1/photos //all of photographer with id 1
有小费吗?
编辑:
“摄影师/{id}/照片/{photoID}”--似乎做得很好,但我怎么支持呢?
RedirectToAction<PhotosController>(x => x.Add())
我是MVC的新手。我有一个接受客户端请求的ActionResult,并且我正在尝试使用MVC验证和模型绑定魔术。此操作不返回视图,但根据特定逻辑重定向到其他操作。
我的问题是,有不同类型的请求与不同的模型相关联,并且这些模型是相互排斥的。
示例:
class Model1
{
[Required]
public string PropA;
}
class Model2
{
[Required]
public string PropB;
}
ActionResult内部的逻辑将遵循类似如下的内容:
If Model1 is valid then Red
我有一个关于ASP.NET MVC中的HttpGet和HttpPost方法的问题。
我有两个HttpGet方法。第一次进入页面时,会首先调用Product()。我有一个表单来提交对数据库的更改。我想用RedirectToAction调用Products(MyModel updatedmodel),就像RedirectToAction("Products", model)一样,但它没有调用那个方法。我在重载的HttpGet调用中有一个断点,但是重载方法从未被调用过。
[HttpGet]
public ActionResult Products()
{
// first c
在下面的RedirectToAction中,我想传递一个viewmodel。如何将模型传递到重定向?
我设置了一个断点来检查model的值,以验证模型的创建是否正确。它是正确的,但是结果视图不包含在模型属性中找到的值。
//
// model created up here...
//
return RedirectToAction("actionName", "controllerName", model);
ASP.NET MVC 4 RC
我有一个场景,我想在用户访问页面(GET,而不是POST)时重定向,我想知道如何在ASP.Net MVC中做到这一点。
这是一个场景。我有一个带有多步骤流程向导的控制器。即使不太可能,用户也可能尝试访问步骤1,尽管他已经完成了该步骤。在这种情况下,我想将他重定向到步骤2。
类似于:
public ViewResult Step1(int? id)
{
//Do some stuff and some checking here...
if (step1done)
{
return RedirectToAction("RegisterStep2
在微软的ASP.NET MVC 5中,
如何从帐户控制器的LogOff操作以外的操作中签出用户?几年前,我会使用返回RedirectToAction(" LogOff ","Account"),但是现在它不再起作用了,因为LogOff是一个Post动作(不是GET)。
public ActionResult SomeActionOfSomeController() {
// some logic
return RedirectToAction("LogOut", "Account"); //does not work sin
如何将以下类移植到ASP.NET MVC3?它是基于ASP.NET MVC2的文章的一部分。方法RenderView()已不复存在,并具有不同的参数。
谢谢。
// Test-specific subclass for HomeController. This won't be
// needed in the next release of ASP.NET MVC.
private sealed class TestHomeController : HomeController {
public RouteValueDictionary RedirectValues;
我在visual studio中使用ASP.NET和MVC3,并且有一个关于将对象从一个动作方法(称为Search)传递到另一个动作方法(称为SearchResult)的问题。我试着使用ViewData,但是它不能持久化到SearchResult视图。下面是我的代码片段,来自单个控制器。当从表单收集数据并调用submit时,调用‘'Search’(因此调用了[HttpPost]声明):
[HttpPost]
public ActionResult Search(Search_q Q){
// do some work here, come up with an object of t
在我的ASP.NET核心MVC项目中,当我的浏览器关闭时,我需要删除cookie,这包括我用来创建cookie的代码。
var claims = new List<Claim>()
{
new Claim(ClaimTypes.Name,user.email),
new Claim(ClaimTypes.Role,user.roles)
};
var identity = new Clai