如何在使用ASPmvc4 强类型视图的分部视图中获取数据展示

在新建FileInputStream时使用当前相对路径或者绝对路径作为参数的问题 - 博客频道 - CSDN.NET
日,一年之约。雾散天晴昏睡的人也从梦中醒来、日,我再次回来。
分类:JAVA
当new一个FileInputStream时,想使用相对路径这样无论我的服务端部署到哪里,都可以一直用一个文件夹而不必修改程序的路径代码,当然首先我用的绝对路径来做实验,保证能够成功通信,使用绝对路径时要注意路径的分隔符可以用“/”或者“\\”,而这也可以混用,如下:FileInputStream fis=new FileInputStream("D:/images/"+id+".jpg");或者FileInputStream fis=new FileInputStream("D:\\images\\"+id+".jpg");都行。甚至可以/与\\混合使用。然后我想用相对路径了,但是当我将images这个文件夹与我的.class文件(即要执行的webservice)放在同一个目录里时,发现运行失败了,提示找不到这个文件夹,代码如下:FileInputStream fis=new FileInputStream("images/"+id+".jpg");然后我就用System.out.println(new File(".").getAbsolutePath());打印了一下当前目录结果是tomcat的bin目录,而并不是tomcat里所部属的webservice目录,遂修改如下:FileInputStream fis=new FileInputStream("../webapps\\axis2\\WEB-INF/pojo/images/"+id+".jpg");注意:../表示当前目录的上一级目录。所以说,当作为webservice部署到tomcat里时,若想使用当前目录,最好先使用System.out.println(new File(".").getAbsolutePath());查看一下当前目录是什么,因为他不一定是你的.class文件存放的目录,通常是tomcat的bin目录,所以需要根据这个目录重新指定你想要到达的目录。
排名:第7049名
(3)(26)(1)(4)(2)(22)(7)(4)(3)(5)(27)(11)(27)(12)(21)(32)(27)(28)(16)(78)(6)(7)(1)(1)匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。38893人阅读
ASP.NET(17)
有Index视图如下:
视图代码如下:
&%@ Page Language=&C#& MasterPageFile=&~/Views/Shared/Site.Master& Inherits=&System.Web.Mvc.ViewPage& %&
&asp:Content ID=&Content1& ContentPlaceHolderID=&TitleContent& runat=&server&&
&/asp:Content&
&asp:Content ID=&Content2& ContentPlaceHolderID=&MainContent& runat=&server&&
&h2&&%= Html.Encode(ViewData[&Message&]) %&&/h2&
&% using(Html.BeginForm(&HandleForm&, &Home&)) %&
Enter your name: &%= Html.TextBox(&name&) %&
&br /&&br /&
Select your favorite color:&br /&
&%= Html.RadioButton(&favColor&, &Blue&, true) %& Blue &br /&
&%= Html.RadioButton(&favColor&, &Purple&, false)%& Purple &br /&
&%= Html.RadioButton(&favColor&, &Red&, false)%& Red &br /&
&%= Html.RadioButton(&favColor&, &Orange&, false)%& Orange &br /&
&%= Html.RadioButton(&favColor&, &Yellow&, false)%& Yellow &br /&
&%= Html.RadioButton(&favColor&, &Brown&, false)%& Brown &br /&
&%= Html.RadioButton(&favColor&, &Green&, false)%& Green
&br /&&br /&
&%= Html.CheckBox(&bookType&) %& I read more fiction than non-fiction.&br /&
&br /&&br /&
My favorite pet: &%= Html.DropDownList(&pets&) %&
&br /&&br /&
&input type=&submit& value=&Submit& /&
&/asp:Content&
如图填写表单数据:
分别使用不同的表单处理方法,对提交的表单数据在视图FormResults呈现。
提交表单对应的HomeController,包含以不同方法获取表单数据的代码,如下:
using System.Collections.G
using System.L
using System.W
using System.Web.M
namespace HtmlHelper.Controllers
[HandleError]
public class HomeController : Controller
public ActionResult Index()
ViewData[&Message&] = &欢迎使用 ASP.NET MVC!&;
//手动构造页面中下拉框的宠物数据
List&string& petList = new List&string&();
petList.Add(&Dog&);
petList.Add(&Cat&);
petList.Add(&Hamster&);
petList.Add(&Parrot&);
petList.Add(&Gold fish&);
petList.Add(&Mountain lion&);
petList.Add(&Elephant&);
ViewData[&Pets&] = new SelectList(petList);
return View();
public ActionResult About()
return View();
/// &summary&
/// 处理表单提交数据,方法1:使用传统的Request请求取值
/// &/summary&
/// &returns&&/returns&
public ActionResult HandleForm()
ViewData[&name&] = Request[&name&];
ViewData[&favColor&] = Request[&favColor&];
ViewData[&bookType&] = Request[&bookType&];
ViewData[&pet&] = Request[&pets&];
return View(&FormResults&);
/// &summary&
/// 处理表单提交数据,方法2:Action参数名与表单元素name值一一对应
/// &/summary&
/// &param name=&name&&&/param&
/// &param name=&favColor&&&/param&
/// &param name=&bookType&&&/param&
/// &param name=&pets&&&/param&
/// &returns&&/returns&
//public ActionResult HandleForm(string name, string favColor, Boolean bookType, string pets)
ViewData[&name&] =
ViewData[&favColor&] = favC
ViewData[&bookType&] = bookT
ViewData[&pet&] =
return View(&FormResults&);
/// &summary&
/// 处理表单提交数据,方法3:从MVC封装的FormCollection容器中读取
/// &/summary&
/// &param name=&form&&&/param&
/// &returns&&/returns&
//public ActionResult HandleForm(FormCollection form)
ViewData[&name&] = form[&name&];
ViewData[&favColor&] = form[&favColor&];
ViewData[&bookType&] = form[&bookType&];
ViewData[&pet&] = form[&pets&];
return View(&FormResults&);
/// &summary&
/// 处理表单提交数据,方法4:使用实体作为Action参数传入,前提是提交的表单元素名称与实体属性名称一一对应
/// &/summary&
/// &param name=&request&&&/param&
/// &returns&&/returns&
//[HttpPost]
//public ActionResult HandleForm(InforModel infor)
ViewData[&name&] = infor.
ViewData[&favColor&] = infor.favC
ViewData[&bookType&] = infor.bookT
ViewData[&pet&] = infor.
return View(&FormResults&);
在FormResults视图显示ViewData的数据,如图所示:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:592194次
积分:5934
积分:5934
排名:第3783名
原创:98篇
转载:49篇
评论:52条
(1)(2)(1)(1)(1)(3)(1)(2)(1)(5)(1)(1)(2)(1)(1)(4)(3)(1)(2)(4)(1)(3)(1)(5)(2)(5)(6)(2)(2)(13)(1)(2)(3)(4)(1)(2)(5)(5)(5)(2)(8)(6)(13)(3)(9)(2)(1)js使用location的方法实验 - 博客频道 - CSDN.NET
日,一年之约。雾散天晴昏睡的人也从梦中醒来、日,我再次回来。
分类:JavaScript
&!DOCTYPE html&
&meta charset=&utf-8& /&
&title&&/title&
function newDoc() {
window.location.assign(&.cn&)
document.write(&&h2&location.hostname 返回 web 主机的域名&/h2&& + location.hostname + &&hr /&&);
document.write(&&h2&location.port 返回 web 主机的端口 (80 或 443)&/h2&& + location.port + &&hr /&&);
document.write(&&h2&location.protocol 返回所使用的 web 协议(http:// 或 https://)&/h2&& + location.protocol + &&hr /&&);
document.write(&&h2&location.pathname 返回当前页面的路径和文件名&/h2&& + location.pathname + &&hr /&&);
&input type=&button& value=&加载新文档& onclick=&newDoc()&&
排名:第7049名
(3)(26)(1)(4)(2)(22)(7)(4)(3)(5)(27)(11)(27)(12)(21)(32)(27)(28)(16)(78)(6)(7)(1)(1)}

我要回帖

更多关于 asp.net 分部视图 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信