Reputation: 4116
My problem is:
I have two fields, and when i call my @Html.Actionlink method it send a null value for these two parameters.
This is my page code:
<div id="new-skill" class="row">
<label for="Description">Descreva brevemente a sua habilidade:</label>
@Html.TextBoxFor(model => model.skill.Description, new { @class = "form-control" })
<label for="Name">Em qual categoria ela está?</label>
@Html.TextBoxFor(model => model.skill.Category.Name, new { @class = "form-control" })
<div class="text-center margin-top15">
@Html.ActionLink("Adicionar nova habilidade", "InsertNewSkill", new
{
professionalId = ViewBag.professionalId,
skillDescription = "Test Text",
categoryName = Model.skill.Category.Name
}, new
{
@class = ""
})
</div>
</div>
This is my InsertNewSkill method:
public ActionResult InsertNewSkill(int professionalId, string skillDescription, string categoryName)
{
initBusinessObjects();
var professional = professionalBusiness.GetById(professionalId);
var newSkill = new SkillModel { Description = skillDescription, Category = new SkillCategoryModel { Name = categoryName } };
skillBusiness.Insert(newSkill);
professional.Skills.Add(newSkill);
professionalBusiness.Update(professional);
return View();
}
What I must to do to achieve this (send the textbox values)?
Upvotes: 1
Views: 1294
Reputation: 1466
Have you tried adding the controllerName to your actionLink?
@Html.ActionLink("Adicionar nova habilidade", "InsertNewSkill","CONTROLLER_NAME", new
{
professionalId = ViewBag.professionalId,
skillDescription = "Test Text",
categoryName = Model.skill.Category.Name
}, new
{
@class = ""
})
Upvotes: 1
Reputation: 39807
Without using jQuery / javascript, you should use a form to get those values back to the server.
@{using(Html.BeginForm("InsertNewSkill", "ControllerName", FormMethod.Get)){
<div id="new-skill" class="row">
<label for="Description">Descreva brevemente a sua habilidade:</label>
@Html.TextBoxFor(model => model.skill.Description, new { @class = "form-control" })
<label for="Name">Em qual categoria ela está?</label>
@Html.TextBoxFor(model => model.skill.Category.Name, new { @class = "form-control" })
@Html.Hidden("professionalId", ViewBag.professionalId)
<div class="text-center margin-top15">
<input type="submit" value="Adicionar nova habilidade"/>
}}
With that said, typically you should POST these values back to the server and then redirect to a new ActionMethod (Thus, the acronym PRG for Post, Redirect, Get).
Upvotes: 0