Home Using a Razor Helper in Htmk.BeginForm() Body
Reply: 0

Using a Razor Helper in Htmk.BeginForm() Body

Redman
1#
Redman Published in 2018-01-10 15:31:29Z

My Problem is that the "Html.BeginForm()" does not find the tag:name in the helper function. The action "Details" in the "ProdukteController" takes a FormCollection as argument. When i try to access formcollection.name I can only access the value "kategorie" which is in the same file as the "Html.BeginForm()". As you see, my helpers generate a dropdown with optgroup and the opt tag which are selectable. As mentioned i cant access the data selected by the user in the helper. Using Html.BeginForms() in the helper is not possible. I tried uncludeing @using System.Web.Mvc.Html; in the helper but that didnt work. ( I left out the databaseconnections in the helpers so we dont have too much code in here)

Thanks for reading and thanks in advance for your help!

using (Html.BeginForm("Details", "Produkte"))
        {
            <form>
                <div style="padding-top:10px">
                    <select  name="kategorie" id="dropdown">
                        @LH.oberkat();
                    </select>
                </div>
                <div>
                    <div>
                        <div><label class="unselectable"><input type="checkbox" name="verf├╝gbar" style="margin-right:5px">nur verf├╝gbare</label></div>
                        <div><label class="unselectable"><input type="checkbox" name="vegetarisch" style="margin-right:5px">nur vegetarisch </label></div>
                        <div><label class="unselectable"><input type="checkbox" name="vegan" style="margin-right:5px">nur vegan </label></div>
                    </div>
                </div>
                <div style="margin-bottom:10px"><button type="submit" class="btn btn-info btn-block">Speisen filtern</button></div>
            </form>
        }


helper.oberkat
while (r.Read())
{
    if (r["pk_ID_Kategorie"].ToString() == r["Oberkategorie"].ToString())
    {
            <optgroup label="@r["Bezeichnung"].ToString()">
                @unterkat(r["pk_ID_Kategorie"].ToString())
            </optgroup>

    }
}

helper.unterkat
 while (r.Read())
        {
            if (r["Oberkategorie"].ToString() == oberkat && kategorie.ToString() == @r["pk_ID_Kategorie"].ToString())
            {
                <option value="@r["pk_ID_Kategorie"]" selected name="@r["pk_ID_Kategorie"]">@r["Bezeichnung"]</option>
            }
            else if (r["Oberkategorie"].ToString() == oberkat)
            {
                <option value="@r["pk_ID_Kategorie"]" name="@r["pk_ID_Kategorie"]"> @r["Bezeichnung"]</option>
        }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.533934 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO