开发者

Create User by profession - How to Populate/Submit/Validate form?

开发者 https://www.devze.com 2023-01-15 09:07 出处:网络
I am trying to create user by registration form which contains dropdown for profession in ASP.NET MVC

I am trying to create user by registration form which contains dropdown for profession in ASP.NET MVC

Eg. Individual, professional, manager etc.

some fields are common like name & Last Name...

开发者_高级运维

some fields are unique by profession...

how do i program it with ajax.

Thanks


I do this sort of thing by creating a SelectList in a controller and passing it to the view as part of a view model. Then in the view, I have the option of doing something when the SelectedValue changes, or simply returning the value of the dropdown when something else triggers a call to a controller.

Controller code:
            int count = 0;
            List<string> YearList = new List<string>();
            for (int i = 2000; i < (DateTime.Now.Year + 6); i += 4)
            {
                YearList.Add(i.ToString());
                if (i < iyear)
                    count++;
            }
            var q = from c in doc.Descendants("candidate")
                    select new can_sw_model
                    {
                        name = c.Attribute("name").Value,
                        office = c.Parent.Attribute("name").Value.ToUpper(),
                        party = c.Attribute("party").Value,
                    };
            can_sw_view model = new can_sw_view()
            {
                YearList = new SelectList(YearList),
                value = YearList[count],
                model = q,
            };
            return View(model);

View code:
    <script type="text/javascript">
        $(document).ready(function() {
            $('#YearList').val('<%= Model.value %>');
            $('#YearList').change(function(event) {
                window.location.replace('<%= ResolveUrl("~/Candidate/sw_candidates") %>' + "?year=" + $('#YearList').val());
            });
        });
        function pdfclick() {
            var grid = $("#grid1").data("tGrid");
            window.location.replace('<%= ResolveUrl("~/Candidate/pdf") %>' + "?year=" + $('#YearList').val() + "&tab=statewide" +
                "&page=" + grid.currentPage + "&orderBy=" + grid.orderBy + "&groupBy=" + grid.groupBy + "&filterBy=" + grid.filterBy);
        }
    </script>

I hope this helps! Bob

0

精彩评论

暂无评论...
验证码 换一张
取 消