Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
<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
C#
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; }
}

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
Posted
Updated 2-Jul-12 23:04pm
v4
Comments
Shahin Khorshidnia 13-Feb-12 11:28am    
French exception?!

Windows version? 7? 2008 Server? ...

1 solution

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.
 
Share this answer
 
v2
Comments
[no name] 13-Feb-12 16:43pm    
Think you for your answers, i ve made some modification.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900