English 中文(简体)
“代码隐藏”局部视图的最佳实践
原标题:Best Practice with "Code Behind" partial views

G天全部。

我对MVC这个东西还是个新手,正在努力了解一些设计基础知识。

我有一个控件(旧的网络表单行话?),我想在多个页面上使用。这是一个标准的登录框,即用户名、密码等,带有提交按钮和特定代码。

我将此创建为局部视图。这在使用它的两个页面/视图中都很好,但我的问题是,当表单(在部分视图中)提交时,将激发的代码放在哪里是最好的位置?

我是否在两个完整视图中都创建HTTPPost属性,然后调用另一类具有特定与部分视图相关代码的通用函数?理想情况下,我想我想要一个“SharedController”或具有类似操作方法的东西,但随着应用程序的增长,这一切似乎都会失控。

我希望这一切都有意义。提前感谢,

Z

最佳回答

一般来说,如果您希望在分解主视图的某个部分时使用局部视图(RenderPartial),请假设您正在渲染主模型之外的复杂类型。

对于你想要的,我认为使用RenderAction将是最好的选择。您将创建一个单独的Logon控制器,并且您的部分视图将绑定到此控制器。基本上,您的登录控件是一个独立的功能单元,宿主视图不需要对此有任何了解。

RenderAction将为LogonController单独完成整个控制器生命周期,您的表单将发布回该控制器。

问题回答

暂无回答




相关问题
WebForms and ASP.NET MVC co-existence

I am trying to make a WebForms project and ASP.NET MVC per this question. One of the things I ve done to make that happen is that I added a namespaces node to the WebForms web.config: <pages ...

Post back complex object from client side

I m using ASP.NET MVC and Entity Framework. I m going to pass a complex entity to the client side and allow the user to modify it, and post it back to the controller. But I don t know how to do that ...

Create an incremental placeholder in NHaml

What I want to reach is a way to add a script and style placeholder in my master. They will include my initial site.css and jquery.js files. Each haml page or partial can then add their own required ...

asp.net mvc automapper parsing

let s say we have something like this public class Person { public string Name {get; set;} public Country Country {get; set;} } public class PersonViewModel { public Person Person {get; ...

structureMap mocks stub help

I have an BLL that does validation on user input then inserts a parent(PorEO) and then inserts children(PorBoxEO). So there are two calls to the same InsertJCDC. One like this=>InsertJCDC(fakePor)...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

热门标签