访问未绑定到模型的控件的值 [英] Accessing the values from controls that are not bound to a model

查看:101
本文介绍了访问未绑定到模型的控件的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我刚开始使用ASP.NET MVC3 / 4而且我已经打到了第一面墙。我有一个模型类和一个强类型的视图,显然是一个控制器。此视图有一个WebGrid,它定义了几个绑定到模型的列和两个日期列(基本上是文本框),即不属于模型类的开始日期和结束日期。最后,有一个ActionLink,当点击时通过传递相应记录的id与控制器对话。



继续我现在被困的地方,我还需要将开始和结束日期传递给控制器​​,但我不知道如何访问日期文本框中的值。我使用jQuery DatePicker小部件在这些文本框中选择日期,但与常规ASP.NET不同,似乎没有办法只做一个txtStartDate.Text或在模板化列中执行FindControl。



My View标记如下:



Hi guys,

I have just started out with ASP.NET MVC3/4 and I have hit my first wall. I have a model class and a view that is strongly typed to it and obviously a controller. This view has a WebGrid that defines several columns that are bound to the model and 2 date columns (text boxes basically), i.e. Start Date and End Date that are not part of the model class. Finally, there is a ActionLink that when clicked talks to the controller by passing the id of the corresponding record.

Heres where I am stuck now, i also need to pass the start and end dates to the controller but I just can''t figure out how to access the date values from the text boxes. I am using jQuery DatePicker widget to select a date in those text boxes but unlike regular ASP.NET there seems to be no way to just do a "txtStartDate.Text" or do a FindControl in a templated column.

My View markup looks like so:

@model IEnumerable<Models.BusinessObject1>

@{
    var mvcgrid = new WebGrid(Model);    
}

<script type="text/javascript">
    $(document).ready(function () {
        $("#txtStartDate").datepicker();
        $("#txtEndDate").datepicker();
    });
</script>

<div id="Grid">
    @mvcgrid.GetHtml(columns: mvcgrid.Columns(
                                              mvcgrid.Column("BOName", "Name"),
                                              mvcgrid.Column(null, "Start Date", format: (item) => Html.TextBox("txtStartDate")),
                                              mvcgrid.Column(null, "End Date", format: (item) => Html.TextBox("txtEndDate")),
                                              mvcgrid.Column(format: (item) => Html.ActionLink("Test","Check",new{selectedid =item.ID, startdate = ??, enddate = ??}))))
</div>





我知道这听起来很漂亮MVC101-ish,但我我看了很多,找不到能帮助我的东西,可能是我看不够,所以如果有人能帮我这个就会很棒。



谢谢。



I know this sounds pretty MVC101-ish, but I have looked quite a lot and couldn''t find something that would help me, may be I haven''t looked enough so if anyone can help me with this it will be awesome.

Thanks.

推荐答案

document )。ready( function (){
(document).ready(function () {


# txtStartDate)。datepicker();
("#txtStartDate").datepicker();


# txtEndDate)日期选择器();
});
< / script >

< div id = 网格 >
@ mvcgrid.GetHtml(columns:mvcgrid.Columns(
mvcgrid.Column(BOName,Name),
mvcgrid.Column(null,Start Date,格式:(item)=> Html.TextBox(txtStartDate)),
mvcgrid.Column(null,结束日期,格式:( item)=> Html.TextBox(txtEndDate)),
mvcgrid.Column(格式:(item)=> Html.ActionLink( 测试,检查,新{selectedid = item.ID,星tdate = ??,enddate = ??}))))
< / div >
("#txtEndDate").datepicker(); }); </script> <div id="Grid"> @mvcgrid.GetHtml(columns: mvcgrid.Columns( mvcgrid.Column("BOName", "Name"), mvcgrid.Column(null, "Start Date", format: (item) => Html.TextBox("txtStartDate")), mvcgrid.Column(null, "End Date", format: (item) => Html.TextBox("txtEndDate")), mvcgrid.Column(format: (item) => Html.ActionLink("Test","Check",new{selectedid =item.ID, startdate = ??, enddate = ??})))) </div>





我知道这听起来很漂亮MVC101-ish,但我我看了很多,找不到能帮助我的东西,可能是我看不够,所以如果有人能帮我这个就会很棒。



谢谢。



I know this sounds pretty MVC101-ish, but I have looked quite a lot and couldn''t find something that would help me, may be I haven''t looked enough so if anyone can help me with this it will be awesome.

Thanks.


这篇关于访问未绑定到模型的控件的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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