请一个没有实体框架的简单MVC3应用程序 [英] Please a simple MVC3 applicaiton without entity framework

查看:66
本文介绍了请一个没有实体框架的简单MVC3应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我试图在MVC3中找到一个简单的应用程序,它与实体框架没有任何关系.
我需要的是一页(视图),一个文本框和一个按钮.我们应该能够在文本框中输入一些文本,并在按下按钮时对文本进行建模,以使一个简单的函数可以使其大写并返回字符串.

然后在同一视图(页面)或另一页面上显示此上调的文本.
因此,这是一个简单的应用程序,可以看到View Controller和Model如何相互交谈.

Hi all,
I was trying to find a simple appliation in MVC3 which does not have to do anything with entity framework.
all I need is one page(view) with one text box and one button. we should be able to enter some text in textbox and upon pressing button the text should got to model where a simple function can make it upper case and return string.

then this uppercsed text deisplayed on same view(page) or another page.
so a simple applicaiton where one can see how View Controller and Model talk to each other. that is all thanks.

推荐答案

1)在开发计算机上安装MVC3.
2)打开Visual Studio 2010
3)创建一个新项目->可视C#->网页-> ASP.NET MVC 3 Web应用程序
4)点击确定
5)Voila,您有一个不使用Entity Framework的功能齐全的MVC3应用程序.
6)在主页/索引"视图上创建一个文本框,并提供适当的Controller方法.
7)提出一个关于您将在哪里失败的代码的问题,我们愿意回答.
1) Install MVC3 on your development machine.
2) Open Visual Studio 2010
3) Create a new Project -> Visual C# -> Web -> ASP.NET MVC 3 Web Application
4) Hit OK
5) Voila, you have a fully functional MVC3 Application that doesn''t use Entity Framework.
6) Create a textbox on you Home/Index view and provide the appropriate Controller method.
7) Ask a question about the code where you fail that we will be willing to answer.


首先,我很抱歉提出一个看起来像是对代码的请求的问题.这不是我的初衷.可能是我没有仔细选择我的话.我想要的是一种无需实体框架即可在视图,控制器和模型之间传递信息的方法.请注意,我的母语不是英语,这可能会引起混淆.
我一直在做一些研究,所以我将向可能有相同问题的人解释我学到的知识,并会转到此页面.
提交表单后,可以通过以下方法将视图中的值返回给控制器.假设我在窗体(视图)中有一个名为"txtBox"的文本框,并且想要将任何用户键入的内容传递回控制器.

1. FormCollection对象
FormCollection是内置对象,它使您可以访问表单的所有控件.
First of all my apologies for asking a question which looks like a request for a code, however it was not my original intention. May be I have not choose my words carefully. All I wanted was a way to pass information between views, controller and models without Entity FrameWork. Please note my first language is not English that may cause the confusion.
I have been doing some research so I will explain what I learn, for those who may have same issues and would come to this page.
There are following ways to get values from view back to controller after submitting the form. lets assume I have a text box in my form(View) named "txtBox" and I want to pass whatever user types in, back to controller.

1. FormCollection object
FormCollection is builtin object, which will give you access to all controls of the form.
public ActionResult Index (FormCollection col) {
string str = col["txtBox"];
}



2.请求对象



2. Request object

public ActionResult Index () {
string str = Request["txtBox"];
}



3.我无法命名,但这是一个简单的参数传递.请注意,参数名称应与控件名称相同(在本例中为txtBox).您可以具有多个参数,具体取决于您要访问的控件的数量.我同意这不是一个很漂亮的方法,但是它可以工作.



3. I can''t name it but it is a simple parameter passing. please note that name of parameter should be same as name of control(in this case txtBox). you can have multiple parameters depending upon number of controls you want to access. I agree not a very pretty way, but it works.

public ActionResult Index (string txtBox) {
string str = txtBox;
}



当然,我们可以选择将视图绑定到模型,然后将该模型对象传递回控制器.



and ofcourse we have the option to tie your view to Model and then pass that model object back to controller.


这篇关于请一个没有实体框架的简单MVC3应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆