站点图标 久久日记本

话说网络硬盘(1)

最近要做一个项目,说是实习结束前的最后一个项目,曰:在线OA。

负责网络硬盘方面的代码,所以顺便梳理一下在MVC3框架下的一些知识。这些我所遇到的问题依次解决之后,网络硬盘也就搞定了。

项目框架:MVC3

项目模板:网络硬盘

涉及表:R_User中的ID,UserName,I_NetDisk的UserID,其中UserID是ID的外键。

问题一:遇到需要权限用户修改自己上传文件的文件名时,其中需要显示文件上传者,这里设置显示框是dropdownlist,要求只能下拉,但是部分item没法选中。

传送门

在WF上可以很轻易实现,两种:

1.设置readonly为true,居然还可以下拉;

2.想到只要在View层设置disabled为true即可,于是用JQuery但是Controller中却无法获得被设置的dropdownlist的value值,很蛋疼的事。很明显,View层是前台代码根据droplist来寻找到值的,若是设置了disabled,据我推测,这样导致前台找不到dropdownlist,也就获取不到值。

怎么办?

我在上面加个隐藏文本域绑定

@Html.HiddenFor(model => model.UserID)
@Html.DropDownList("UserID")

但是这样虽然获取到了值,disabled却失去了作用,dropdownlist照样能够下拉。

实在没办法

我只能用UserID代替UserName显示上传人编号了,

@Html.DropDownList("UserID")//显示的是所有的UserName信息

改为

@Html.Label("UserID")

但是这个就显得效果不好,因为当用户修改“文件名”,看到的编辑页码信息却是“上传者ID”,可不可以,有更好的方法呢?

效果图:

代码:

@model inOffice.Models.I_NetDisk

@{
    ViewBag.Title = "Edit";
}

<h2>编辑</h2>

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="http://www.cnblogs.com/Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#UserID").attr("readonly", true);
        $("#Type").attr("readonly", true);
        $("#UserID").attr("enable", false);
        $("#Pid").attr("readonly", true);
        $("#FilePath").attr("readonly", true);
        $("#FileType").attr("readonly", true);
    });
</script>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>网络硬盘</legend>

        @Html.HiddenFor(model => model.ID)

        <div class="editor-label">
            拥有者ID
@*            @Html.LabelFor(model => model.UserID, "R_User")*@
        </div>
        <div class="editor-field">
@*              @Html.Label("UserID")*@
@*            @Html.HiddenFor(model => model.UserID)*@
@*            @Html.DropDownList("UserID")*@

            @Html.EditorFor(model => model.UserID)
 @*           @Html.EditorFor(model => model.R_User.UserName)*@
@*            @Html.Label(Request.Cookies["UserName"].Value)*@
            @Html.ValidationMessageFor(model => model.UserID)
        </div>

        <div class="editor-label">
            类型
@*            @Html.LabelFor(model => model.Type)*@
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Type)
            @Html.ValidationMessageFor(model => model.Type)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Pid)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Pid)
            @Html.ValidationMessageFor(model => model.Pid)
        </div>

        <div class="editor-label">
            文件名
@*            @Html.LabelFor(model => model.Name)*@
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.FilePath)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FilePath)
            @Html.ValidationMessageFor(model => model.FilePath)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.FileType)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FileType)
            @Html.ValidationMessageFor(model => model.FileType)
        </div>

        <p>
            <input type="submit" value="保存" />
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("返回文件列表", "Index")
</div>
退出移动版