如何使用模板局部视图将电话号码列表保存在mvc3中 [英] how to use a template partial view to save list of phone numbers in mvc3

查看:80
本文介绍了如何使用模板局部视图将电话号码列表保存在mvc3中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题:我想存储一个电话号码列表,默认情况下,第一个电话号码会以局部视图显示,而其他电话号码是在我按下链接时动态创建的(即:添加电话号码)...
为了做到这一点,我创建了一个模板,其中包含我使用的字段,如下所示:

I have this problem: I want to store a list of phone numbers where the first is rended by default with a partial view, the others are created dynamically when I press a link (i.e.: Add Phone number)...
In order to do this, I created a template with the fields I use, that is the following:

<div class="editor-label">
@Html.Label("Contact type")
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.CatContact[0], (ViewData["catcontact"] as SelectList), "---    ")
</div>
<div style="clear: both;">
<div class="divpos" style="width: 760px !important;">
    <div class="editor-label">
        @Html.Label("Phone number")
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.PrefI[0]) <!--International prefix-->
        @Html.ValidationMessageFor(model => model.PrefI[0])
        @Html.EditorFor(model => model.PrefN[0]) <!--National prefix-->
        @Html.ValidationMessageFor(model => model.PrefN[0])
        @Html.EditorFor(model => model.Number[0]) <!--Phone Number-->
        @Html.ValidationMessageFor(model => model.Number[0])
    </div>
</div>
</div>



此局部视图采用以下模型



This partial view takes the following model

public partial class RegView1Model
{
    /// <summary>
    /// Contact type
    /// </summary>
    public List<int> CatContact { get; set; }
    /// <summary>
    /// International prefix
    /// </summary>
    public List<string> PrefI { get; set; }
    /// <summary>
    /// National prefix
    /// </summary>
    public List<string> PrefN { get; set; }
    /// <summary>
    /// Phone number
    /// </summary>
    public List<string> Number { get; set; }
}


我想一次保存所有电话号码.我还试图通过添加所有呈现的代码以及先前HTML的简单复制/粘贴来找到jQuery的解决方案,但是当然这并不容易维护.
所以我的问题是,是否有可能每次我用剃刀在mvc3中按下链接时都渲染局部视图,从而在不使用javascript(或jQuery)的情况下增加列表的索引
希望我已经很好地解释了我的问题


I want to save all phone numbers at once. I''ve also tried to find a solution with jQuery, by adding all the rendered code with a simple copy/paste of the previous HTML, but of course it is not easy to maintain.
So my question is if it is possible to render the partial view each time I press a link in mvc3 with razor, increasing the index of the lists without using javascript (or jQuery)
Hope I''ve explained well my problem

推荐答案

您的代码在任何步骤中都不会检查返回值.您需要这样做,所以它永远不会崩溃.然后,您需要查看正在爆炸的那一行,找出哪个对象为空,并读取返回该对象的方法的文档,以便可以找出正在发生的情况.一种猜测是localMachine.Children.Find找不到用户并返回null,在这种情况下,我猜您的字符串格式错误.

如果您阅读文档,则您的代码需要以admin身份运行才能拥有请求此值的权利.如果您不是管理员,则会返回null.在Vista或Windows 7中,您需要设置清单文件以告诉您的代码请求管理员权限,而以admin身份登录是不够的.
Your code does not check return values any step of the way. You need to do that, so it will never blow up. Then you need to look at the line that is blowing up, work out what object is null and read the documenation for the method that returned it, so you can work out what is going on. One guess is that localMachine.Children.Find is not finding the user and is returning null, in which case I''d guess the format of your string is wrong.

If you read the docs, your code needs to run as admin to have the right to request this value. If you''re not an admin, you get null back. In Vista or Windows 7, you need to set your manifest file to tell your code to request admin rights, being logged in as admin is not enough.


这篇关于如何使用模板局部视图将电话号码列表保存在mvc3中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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