0

i have textbox

@Html.TextBox("report_id", null, new { @class = "form-control col-md-7 col-xs-12", @Value = @ViewBag.Reports_ID, @readonly = true })

i want use actionlink to send textbox value to controller. but i can't get textbox value.

@Html.ActionLink("Preview", "Update", "Home", new { @report_id = Request.QueryString["report_id "] }, new { @class = "btn btn-info", target = "_blank" })

Pls help, Thanks

2
  • You need javascript to update the href attribute of the link based on the edited value in the textbox (or just enclose the textbox in a form with FormMethod.Get. And there is no point adding new { @report_id = Request.QueryString["report_id "] } - that's just adding the original value of report_id Commented Oct 20, 2016 at 7:08
  • Take a look at stackoverflow.com/questions/31581409/… Commented Oct 20, 2016 at 8:55

1 Answer 1

1

First give an ID attribute to the action link like below:

@Html.ActionLink("Preview", "Update", "Home", new { @report_id = Request.QueryString["report_id "] }, new { @class = "btn btn-info", target = "_blank", id="alink" })

Then write a jQuery click event function for the ActionLink:

$("#alink").click(function () {
    $(this).attr("href", $(this).attr("href") + "?id=" + $("#report_id").val());
});

See if it will work for you.

Sign up to request clarification or add additional context in comments.

4 Comments

Hi Faisal, Thanks
Hi @Faisal, follow you code, i can get textbox id. But I press "preview" button 2 times more, address link will general so much "report_id". see "/Reports/Home/Update?report_id=161024001?report_id=161024001?report_id=161024001".
In that case need to check if the id parameter already exists before adding it again. Something like: var url =$(this).attr("href"); if(url.indexOf('?report_id=') == -1) {$(this).attr("href", $(this).attr("href") + "?report_id=" + $("#report_id").val());}
Great! Glad to know that it helped you. Please mark the answer.

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.