texbox value is not showing in url
i want to send text box value to controller in action as a 2nd parameter.
first parameter is id and second one is myval.
here is view code:
@model System.ValueTuple<System.Data.DataTable,websitetemplate.Models.ChartQuantity>
<div class="container">
<div class="row">
<div class="col-md-12 nopadding">
<div class="col-md-4 col-sm-4">
<div class="section-2-box-left wow fadeInLeft">
@if (Model.Item1.Rows.Count > 0)
{
string myimage = Model.Item1.Rows[0][4].ToString();
<div style="margin-bottom:10px; "><figure><img src="~/image/@myimage" /></figure></div>
<div style="margin-top:2px;">
<p>Title:@Model.Item1.Rows[0][1]</p>
<p>Description:@Model.Item1.Rows[0][2]</p>
<p>Price: $ @Model.Item1.Rows[0][3]</p>
<label>Quantity:</label>
@Html.TextBoxFor(model=>model.Item2.quantity, new { Type = "Number" })<br />
</div>
string val = Model.Item2.quantity.ToString();
<a href="@Url.Action("chart", "Chart", new { id = Model.Item1.Rows[0][0], myval=Model.Item2.quantity })" class="btn btn-primary">Add to chart</a>
}
else
{
<div>
<figure><img src="~/image/alt.jpg" /></figure>
</div>
}
</div>
</div>
Here is controller:
public ActionResult chart(int id = 0, int myval = 0)
{
string val1="",val2="", val3 ="",val5="";
int v=0;
using (SqlConnection conn = new SqlConnection(connection))
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from [dbo].[Admin] Where ID='" + id + "'", conn);
}
Here In View model.Item2.quantity is not passing properly in action link as it is not showing in controller. if any one know, please help me. Thanks.
asp.net-mvc
add a comment |
i want to send text box value to controller in action as a 2nd parameter.
first parameter is id and second one is myval.
here is view code:
@model System.ValueTuple<System.Data.DataTable,websitetemplate.Models.ChartQuantity>
<div class="container">
<div class="row">
<div class="col-md-12 nopadding">
<div class="col-md-4 col-sm-4">
<div class="section-2-box-left wow fadeInLeft">
@if (Model.Item1.Rows.Count > 0)
{
string myimage = Model.Item1.Rows[0][4].ToString();
<div style="margin-bottom:10px; "><figure><img src="~/image/@myimage" /></figure></div>
<div style="margin-top:2px;">
<p>Title:@Model.Item1.Rows[0][1]</p>
<p>Description:@Model.Item1.Rows[0][2]</p>
<p>Price: $ @Model.Item1.Rows[0][3]</p>
<label>Quantity:</label>
@Html.TextBoxFor(model=>model.Item2.quantity, new { Type = "Number" })<br />
</div>
string val = Model.Item2.quantity.ToString();
<a href="@Url.Action("chart", "Chart", new { id = Model.Item1.Rows[0][0], myval=Model.Item2.quantity })" class="btn btn-primary">Add to chart</a>
}
else
{
<div>
<figure><img src="~/image/alt.jpg" /></figure>
</div>
}
</div>
</div>
Here is controller:
public ActionResult chart(int id = 0, int myval = 0)
{
string val1="",val2="", val3 ="",val5="";
int v=0;
using (SqlConnection conn = new SqlConnection(connection))
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from [dbo].[Admin] Where ID='" + id + "'", conn);
}
Here In View model.Item2.quantity is not passing properly in action link as it is not showing in controller. if any one know, please help me. Thanks.
asp.net-mvc
add a comment |
i want to send text box value to controller in action as a 2nd parameter.
first parameter is id and second one is myval.
here is view code:
@model System.ValueTuple<System.Data.DataTable,websitetemplate.Models.ChartQuantity>
<div class="container">
<div class="row">
<div class="col-md-12 nopadding">
<div class="col-md-4 col-sm-4">
<div class="section-2-box-left wow fadeInLeft">
@if (Model.Item1.Rows.Count > 0)
{
string myimage = Model.Item1.Rows[0][4].ToString();
<div style="margin-bottom:10px; "><figure><img src="~/image/@myimage" /></figure></div>
<div style="margin-top:2px;">
<p>Title:@Model.Item1.Rows[0][1]</p>
<p>Description:@Model.Item1.Rows[0][2]</p>
<p>Price: $ @Model.Item1.Rows[0][3]</p>
<label>Quantity:</label>
@Html.TextBoxFor(model=>model.Item2.quantity, new { Type = "Number" })<br />
</div>
string val = Model.Item2.quantity.ToString();
<a href="@Url.Action("chart", "Chart", new { id = Model.Item1.Rows[0][0], myval=Model.Item2.quantity })" class="btn btn-primary">Add to chart</a>
}
else
{
<div>
<figure><img src="~/image/alt.jpg" /></figure>
</div>
}
</div>
</div>
Here is controller:
public ActionResult chart(int id = 0, int myval = 0)
{
string val1="",val2="", val3 ="",val5="";
int v=0;
using (SqlConnection conn = new SqlConnection(connection))
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from [dbo].[Admin] Where ID='" + id + "'", conn);
}
Here In View model.Item2.quantity is not passing properly in action link as it is not showing in controller. if any one know, please help me. Thanks.
asp.net-mvc
i want to send text box value to controller in action as a 2nd parameter.
first parameter is id and second one is myval.
here is view code:
@model System.ValueTuple<System.Data.DataTable,websitetemplate.Models.ChartQuantity>
<div class="container">
<div class="row">
<div class="col-md-12 nopadding">
<div class="col-md-4 col-sm-4">
<div class="section-2-box-left wow fadeInLeft">
@if (Model.Item1.Rows.Count > 0)
{
string myimage = Model.Item1.Rows[0][4].ToString();
<div style="margin-bottom:10px; "><figure><img src="~/image/@myimage" /></figure></div>
<div style="margin-top:2px;">
<p>Title:@Model.Item1.Rows[0][1]</p>
<p>Description:@Model.Item1.Rows[0][2]</p>
<p>Price: $ @Model.Item1.Rows[0][3]</p>
<label>Quantity:</label>
@Html.TextBoxFor(model=>model.Item2.quantity, new { Type = "Number" })<br />
</div>
string val = Model.Item2.quantity.ToString();
<a href="@Url.Action("chart", "Chart", new { id = Model.Item1.Rows[0][0], myval=Model.Item2.quantity })" class="btn btn-primary">Add to chart</a>
}
else
{
<div>
<figure><img src="~/image/alt.jpg" /></figure>
</div>
}
</div>
</div>
Here is controller:
public ActionResult chart(int id = 0, int myval = 0)
{
string val1="",val2="", val3 ="",val5="";
int v=0;
using (SqlConnection conn = new SqlConnection(connection))
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("Select * from [dbo].[Admin] Where ID='" + id + "'", conn);
}
Here In View model.Item2.quantity is not passing properly in action link as it is not showing in controller. if any one know, please help me. Thanks.
asp.net-mvc
asp.net-mvc
asked Dec 28 '18 at 19:35
Adnan aliAdnan ali
186
186
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The Url.Action
helper method gets executed on the server when razor view engine is executing the code in your view. The result of that (HTML) will be send to the browser and then browser will render it. User can edit the value of the input element and there is no way that the href
value of the already rendered link tag gets changed dynamically!
You have 2 options.
1) Do a form submit. You can wrap your input elements inside a form tag and do a form submit. When the form is submitted, it will send the current input element value as well. Make sure your input element name
attribute value matches your action method parameter name.
<form action="chart" method="get">
<input type="number" value="@Model.Item2.quantity" name="myval" />
<input type="hidden" name="id" value="@Model.Item1.Rows[0][0]" />
<button type="submit" class="btn">Add to chart</button>
</form>
2) Using JavaScript. In this approach you will intercept the click event using JavaScript, stop the normal behavior (use preventDefault
method to do so), read the input element value and build the URL with that values you want in that and navigate to that URl by setting the new URL to window.location.href
.
Thanks. First answer is working for me.
– Adnan ali
Jan 9 at 18:38
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53963499%2ftexbox-value-is-not-showing-in-url%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The Url.Action
helper method gets executed on the server when razor view engine is executing the code in your view. The result of that (HTML) will be send to the browser and then browser will render it. User can edit the value of the input element and there is no way that the href
value of the already rendered link tag gets changed dynamically!
You have 2 options.
1) Do a form submit. You can wrap your input elements inside a form tag and do a form submit. When the form is submitted, it will send the current input element value as well. Make sure your input element name
attribute value matches your action method parameter name.
<form action="chart" method="get">
<input type="number" value="@Model.Item2.quantity" name="myval" />
<input type="hidden" name="id" value="@Model.Item1.Rows[0][0]" />
<button type="submit" class="btn">Add to chart</button>
</form>
2) Using JavaScript. In this approach you will intercept the click event using JavaScript, stop the normal behavior (use preventDefault
method to do so), read the input element value and build the URL with that values you want in that and navigate to that URl by setting the new URL to window.location.href
.
Thanks. First answer is working for me.
– Adnan ali
Jan 9 at 18:38
add a comment |
The Url.Action
helper method gets executed on the server when razor view engine is executing the code in your view. The result of that (HTML) will be send to the browser and then browser will render it. User can edit the value of the input element and there is no way that the href
value of the already rendered link tag gets changed dynamically!
You have 2 options.
1) Do a form submit. You can wrap your input elements inside a form tag and do a form submit. When the form is submitted, it will send the current input element value as well. Make sure your input element name
attribute value matches your action method parameter name.
<form action="chart" method="get">
<input type="number" value="@Model.Item2.quantity" name="myval" />
<input type="hidden" name="id" value="@Model.Item1.Rows[0][0]" />
<button type="submit" class="btn">Add to chart</button>
</form>
2) Using JavaScript. In this approach you will intercept the click event using JavaScript, stop the normal behavior (use preventDefault
method to do so), read the input element value and build the URL with that values you want in that and navigate to that URl by setting the new URL to window.location.href
.
Thanks. First answer is working for me.
– Adnan ali
Jan 9 at 18:38
add a comment |
The Url.Action
helper method gets executed on the server when razor view engine is executing the code in your view. The result of that (HTML) will be send to the browser and then browser will render it. User can edit the value of the input element and there is no way that the href
value of the already rendered link tag gets changed dynamically!
You have 2 options.
1) Do a form submit. You can wrap your input elements inside a form tag and do a form submit. When the form is submitted, it will send the current input element value as well. Make sure your input element name
attribute value matches your action method parameter name.
<form action="chart" method="get">
<input type="number" value="@Model.Item2.quantity" name="myval" />
<input type="hidden" name="id" value="@Model.Item1.Rows[0][0]" />
<button type="submit" class="btn">Add to chart</button>
</form>
2) Using JavaScript. In this approach you will intercept the click event using JavaScript, stop the normal behavior (use preventDefault
method to do so), read the input element value and build the URL with that values you want in that and navigate to that URl by setting the new URL to window.location.href
.
The Url.Action
helper method gets executed on the server when razor view engine is executing the code in your view. The result of that (HTML) will be send to the browser and then browser will render it. User can edit the value of the input element and there is no way that the href
value of the already rendered link tag gets changed dynamically!
You have 2 options.
1) Do a form submit. You can wrap your input elements inside a form tag and do a form submit. When the form is submitted, it will send the current input element value as well. Make sure your input element name
attribute value matches your action method parameter name.
<form action="chart" method="get">
<input type="number" value="@Model.Item2.quantity" name="myval" />
<input type="hidden" name="id" value="@Model.Item1.Rows[0][0]" />
<button type="submit" class="btn">Add to chart</button>
</form>
2) Using JavaScript. In this approach you will intercept the click event using JavaScript, stop the normal behavior (use preventDefault
method to do so), read the input element value and build the URL with that values you want in that and navigate to that URl by setting the new URL to window.location.href
.
edited Dec 28 '18 at 20:01
answered Dec 28 '18 at 19:51
ShyjuShyju
144k87330436
144k87330436
Thanks. First answer is working for me.
– Adnan ali
Jan 9 at 18:38
add a comment |
Thanks. First answer is working for me.
– Adnan ali
Jan 9 at 18:38
Thanks. First answer is working for me.
– Adnan ali
Jan 9 at 18:38
Thanks. First answer is working for me.
– Adnan ali
Jan 9 at 18:38
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53963499%2ftexbox-value-is-not-showing-in-url%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown