1

I am creating a simple blog applicaton. I have to add comments to a blog post. I have a line in my code which looks like this:

<input type="hidden" name="Comment.BlogID" value="@Model.Blog.BlogID" />

Basically, I am setting the Comment.BlogID to Model.Blog.BlogID

is there a way to do this using HTML.Hiddenfor.

I tried the code below but that does not work.

@Html.HiddenFor(model => model.Comment.BlogID, new { value = @Model.Blog.BlogID });

2 Answers 2

1

You have to set the value in the model of that view to the actual BlogId, if possible in the controller. If that is not possible you can't change the value which is used in the Html.HiddenFor helper later on. You could try

@{ Model.Comment.BlogId = Model.Blog.BlogId; }
Sign up to request clarification or add additional context in comments.

Comments

0
@Html.Hidden(model.Comment.BlogID, @Model.Blog.BlogID);

Comments

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.