At the moment I have this code:
@using (Html.BeginForm("Add", "Review", "Review"))
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Review</legend>
<div class="editor-label">
@Html.LabelFor(model => model.TEKST)
</div>
<div class="editor-field">
@Html.TextBoxFor(model => model.TEKST)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
This will send me to: localhost:4470/Review/Add?Length=6
The thing that I actually want is this url: localhost:4470/Review/Add?tekst=sdfsdf
How can I modify this code that it will use “tekst” as parameter instead of length? And as value the content of the textbox.
UPDATE:
This are my action methods:
public ActionResult Create()
{
return View();
}
public ActionResult Add(string tekst)
{
ViewBag.test = tekst;
return View();
}
In the View page of Create, I would like to have a form, with a textbox or textarea, that sends an action to Add, the content of the textbox or textarea should be in parameter “tekst” of action method “Add”
SOLUTION:
See the post of CD Smith
I’m not sure what your action looks like but as long as it is accepting your model, you have the value for TEKST in your model..
If you need something different then you’re View would need to be different as well, you post a Model from the view, you don’t send GET parameters by making a POST
Do you have an action that currently takes TEKST as a parameter?
UPDATE
Ok, looking at your action… you don’t need to modify your view, you need to modify your actions, try this this will get you what you want.
Change
YourModelTypeHereto match your real model typeYou need to modify your view just a tad – remove the parameters from the BeginForm tag
So the
Createaction will render theCreateView, then POST back to theCreatemethod that has the[HttpPost]annotation. Then the value ofTEKSTwill be sent as a parameter to theAddmethod as aRedirectToActionand render theAddview