开发者

MVC3 Razor Dynamic creating forms

First I want to point out Im very new to this area ^_^ .

Anyhow

I'm doing a project with a grade-reporting system and now Im currently working with the cshtml for the updat开发者_如何学Goe of usertask.

My problem is

I'm currently working with trying to add a form post but it's not really working at all.

To my view I have a model with a list of usertasks (and other data). These usertasks contains int id and string grade.

What I am trying to do is foreach usertask create a form with their own submit button. The form would have a hidden field for id and a textbox for grading.

The problem i have with @Html.Hidden Compiler Error Message: CS1973: 'System.Web.Mvc.HtmlHelper' has no applicable method named 'Hidden' but appears to have an extension method by that name. Extension methods cannot be dynamically dispatched. Consider casting the dynamic arguments or calling the extension method without the extension method syntax.

Which I assume is you cant dynamicaly use Html.Hidden (i use a foreach loop over the list of usertasks).

Anyone have any idea how to solve this? I've been thinking about creating partialviews but couldnt figure out if you could pass paramters to them. Or make the submit button redirect to a controller-view which takes the 2 paramters?

Anyone have any examples?

Thx for help!

Submitting some code I have been trying to get to work.

foreach (var tskModel in tskgrpModel.usertasks)
        {
            @tskModel.name

            using (Html.BeginForm("Update", "Teacher", FormMethod.Post))
            {
                if(tskModel.isSet == true)
                {
                    @Html.Hidden("ut_id", tskModel.id )
                    @Html.TextBox("ut_grade",(string)@tskModel.grading);
                }
                else
                {
                    @Html.Hidden("ut_id", -1)
                    @Html.Hidden("ut_id", "NotSet")
                }


                
            }

        }


Is taskModel.id a dynamic variable?

if so change the line

@Html.Hidden("ut_id", tskModel.id )

to

@Html.Hidden("ut_id", (int) tskModel.id )
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜