1

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 update 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")
                }


                
            }

        }

1 Answer 1

7

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 )
Sign up to request clarification or add additional context in comments.

1 Comment

I think I didnt explain thorougly. What I want do know is how to create a form which has fields from a List<UserTask> where each usertask has a string property grading. And When I submit I want to in some easy way know which of the UserTasks ( they have uniqe ids) I changed the grading for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.