0

C# は私の日常的な言語ではないので、とても慣れていない

これは私のモデルです

public class SpecialtyListsModels
{
    public Dictionary<int, dynamic> specialties = new Dictionary<int, dynamic>();

    public Dictionary<int, dynamic> SpecialtyLists()
    {
        specialties.Add(1, new {name = "Varun", age = "11"} );
        specialties.Add(2, new {name = "Khushi", age = "12"} );

        return (specialties);
    }
}

これは私のクラスです

public class SignupController : Controller
{
    public ActionResult Index()
    {
        PFSignup.Models.SpecialtyListsModels objSpecialtyList = new PFSignup.Models.SpecialtyListsModels();

        Dictionary<int, dynamic> specialtyLists = objSpecialtyList.SpecialtyLists();

        return View();
    }

    [HttpPost]
    public ActionResult Create(SignupModels signup)
    {
        return View(signup);
    }
}

これは、すべての専門分野のドロップダウン リストを追加するビューです。

<body>
<div>
    @using (Html.BeginForm("Create", "Signup"))
    {
        <label for="first_name">First Name:</label>
        <input type="text" name="first_name" id="first_name" value="" />

        <br />

        <label for="last_name">Last Name:</label>
        <input type="text" name="last_name" id="last_name" value ="" />

        @Html.DropDownList("specialty_list", new SelectList(SpecialtyListModels, ) 

        <input type="submit" name="submit" value="Submit" />
     }
</div>

誰かがドロップダウンリストコードで私を助けてくれますか?ビューの上にリストを追加する必要がありますか?

4

1 に答える 1

0

最初にこのリンクをドキュメントに使用することをお勧めします: http://www.asp.net/mvc/tutorials/javascript/working-with-the-dropdownlist-box-and-jquery/using-the-dropdownlist-helper-with -aspnet-mvc

public class SpecialtyListsModels { public Dictionary の専門分野 = new Dictionary();

    public Dictionary<int, dynamic> SpecialtyLists()
    {
        specialties.Add(1, new {name = "Varun", age = "11"} );
        specialties.Add(2, new {name = "Khushi", age = "12"} );

        return (specialties);
    }
}

これは私のクラスです

public class SignupController : Controller
{
    public ActionResult Index()
    {
        PFSignup.Models.SpecialtyListsModels objSpecialtyList = new PFSignup.Models.SpecialtyListsModels();

        Dictionary<int, dynamic> specialtyLists = objSpecialtyList.SpecialtyLists();

        return View(specialtyLists);
    }

    [HttpPost]
    public ActionResult Create(SignupModels signup)
    {
        return View(signup);
    }
}

これは、すべての専門分野のドロップダウン リストを追加するビューです。

    @model Dictionary<int, dynamic>
    <body>
    <div>
        @using (Html.BeginForm("Create", "Signup"))
        {
            <label for="first_name">First Name:</label>
            <input type="text" name="first_name" id="first_name" value="" />

            <br />

            <label for="last_name">Last Name:</label>
            <input type="text" name="last_name" id="last_name" value ="" />

            @Html.DropDownList("specialty_list", new SelectList(Model) 

            <input type="submit" name="submit" value="Submit" />
         }
    </div>
</body>
于 2013-02-06T07:59:32.543 に答える