Click here to Skip to main content
15,896,526 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
<table cellspacing="5">
    <tr>
        <td>
            <mark>Selectionner Country :</mark>
            @Html.DropDownList("Country",
                        new SelectList(Model, "Code", "Name"),
                        "Select Country 
           new { @class = "form-control", id = "Country" })

        </td>
        <td>...............</td>
        <td>


            <mark>Selectionner le Code Secteur :</mark>
            @Html.DropDownList("Region",
                        new SelectList(Enumerable.Empty<WebApplication_SRP.Controllers.Region>(), "CountryCode", "Name"),
                        "Select Secteur",
                        new { @class = "form-control", id = "Region" })

        </td>
        <td>................</td>
        <td>
            @using (Html.BeginForm("CommDNP3Form", "CommDNP3", FormMethod.Post))
            {
                <mark> Selectionner le Site :</mark>
                @Html.DropDownList("Lsite",
                            new SelectList(Enumerable.Empty<WebApplication_SRP.Controllers.Lsite>(), "CountryCode1", "Name"),
                            "Select Site",
                            new { @class = "form-control", id = "Lsite" })
                @Html.Hidden("hfNom")

            }
        </td>

    </tr>

</table>


What I have tried:

I wanted to recover and keep the value of the third combo. But she is still null:


System.NullReferenceException : 'La référence d'objet n'est pas définie à une instance d'un objet.'

System.Collections.Specialized.NameValueCollection.this[string].get retournée null.
Posted
Updated 13-Dec-19 4:50am
Comments
ZurdoDev 11-Dec-19 15:17pm    
The problem is likely in your controller not filling in a value. From what you have posted, I'm not sure what else we can do to help.

1 solution

Quote:
C#
string nom = formCollection["hfNom"].ToString();
That's the line that's causing the exception, because formCollection["hfNom"] is returning null, and you then try to call .ToString() on it.

But the indexer already returns a string, so you don't need that .ToString() call at all:
C#
string nom = formCollection["hfNom"];

Now you just need to work out why you're not passing a value in that field.
 
Share this answer
 

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