How to send model property value to controller method in K-MVC using @Ko.Html.Button
I am trying to send value of StockDate to Controller Method. I am getting Null.
http://knockoutmvc.com/ParametersToServer
as per above link if I pass static value like below.I can get value but when I use Model.Property I always get Null.
@ko.Html.Button("Inc 3", "Increment", "ParametersToServer", new { value = 3 })
Following is the code..
View Code-
@using PerpetuumSoft.Knockout
@model OpManWeb.ViewModel.Inventory.TransactionHistory
@{
var ko = Html.CreateKnockoutContext();
}
@{
ViewBag.Title = "Add Stock";
}
<script src="~/Scripts/perpetuum.knockout.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
@using (ko.Html.Form("SaveStock", "Inventory"))
{
<div class="row">
<div class="col-md-3 col-lg-3 clmargin">
<div class="form-group col-md-4 zeropadding div2adjustments">
@Html.LabelFor(m => m.StockDate, new { @class = "fieldtext" })
</div>
<div class="col-md-8 div2adjustments">
@ko.Html.TextBox(m => m.StockDate, new { @class = "form-control input-sm fieldtextinput ",
@id="stockdatepicker" })
</div>
</div>
</div>
@ko.Html.Button("Cancel", "sample1", "Inventory", new { value = Model.StockDate}, new { @class = "btn btn- primary maxheightbtn col-md-12", @id = "btn" })
}
Model Code-
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace OpManWeb.ViewModel.Inventory
{
public class TransactionHistory
{
[DisplayName("Stock Date")]
public string StockDate
{
get;
set;
}
}
}
Controller Code-
public ActionResult sample1(string value)
{
return Json(value);
}
I always get null for string value in controller..
Can anyone have faced such issue..?
Help..!!
Thanks In Advance..!!
c# asp.net-mvc razor knockout.js knockout-mvc
|
show 1 more comment
I am trying to send value of StockDate to Controller Method. I am getting Null.
http://knockoutmvc.com/ParametersToServer
as per above link if I pass static value like below.I can get value but when I use Model.Property I always get Null.
@ko.Html.Button("Inc 3", "Increment", "ParametersToServer", new { value = 3 })
Following is the code..
View Code-
@using PerpetuumSoft.Knockout
@model OpManWeb.ViewModel.Inventory.TransactionHistory
@{
var ko = Html.CreateKnockoutContext();
}
@{
ViewBag.Title = "Add Stock";
}
<script src="~/Scripts/perpetuum.knockout.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
@using (ko.Html.Form("SaveStock", "Inventory"))
{
<div class="row">
<div class="col-md-3 col-lg-3 clmargin">
<div class="form-group col-md-4 zeropadding div2adjustments">
@Html.LabelFor(m => m.StockDate, new { @class = "fieldtext" })
</div>
<div class="col-md-8 div2adjustments">
@ko.Html.TextBox(m => m.StockDate, new { @class = "form-control input-sm fieldtextinput ",
@id="stockdatepicker" })
</div>
</div>
</div>
@ko.Html.Button("Cancel", "sample1", "Inventory", new { value = Model.StockDate}, new { @class = "btn btn- primary maxheightbtn col-md-12", @id = "btn" })
}
Model Code-
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace OpManWeb.ViewModel.Inventory
{
public class TransactionHistory
{
[DisplayName("Stock Date")]
public string StockDate
{
get;
set;
}
}
}
Controller Code-
public ActionResult sample1(string value)
{
return Json(value);
}
I always get null for string value in controller..
Can anyone have faced such issue..?
Help..!!
Thanks In Advance..!!
c# asp.net-mvc razor knockout.js knockout-mvc
Have you tried accessingmodel.StockDate
in your controller?
– Inspector Squirrel
Feb 26 '15 at 12:37
Yess I am getting null for string value inside my controller arguement..
– Aditya Raval
Feb 26 '15 at 12:40
That's because you aren't passing a key:value pair with the keyvalue
to the controller.
– Inspector Squirrel
Feb 26 '15 at 12:47
How can we achieve that...?Can you write answer for this question?
– Aditya Raval
Feb 26 '15 at 12:49
I know we can achieve that but i don't want to use the view model. I want to achieve this using parameter value which is passed into @ko.Html.Button..and inside controller its string value
– Aditya Raval
Feb 26 '15 at 12:55
|
show 1 more comment
I am trying to send value of StockDate to Controller Method. I am getting Null.
http://knockoutmvc.com/ParametersToServer
as per above link if I pass static value like below.I can get value but when I use Model.Property I always get Null.
@ko.Html.Button("Inc 3", "Increment", "ParametersToServer", new { value = 3 })
Following is the code..
View Code-
@using PerpetuumSoft.Knockout
@model OpManWeb.ViewModel.Inventory.TransactionHistory
@{
var ko = Html.CreateKnockoutContext();
}
@{
ViewBag.Title = "Add Stock";
}
<script src="~/Scripts/perpetuum.knockout.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
@using (ko.Html.Form("SaveStock", "Inventory"))
{
<div class="row">
<div class="col-md-3 col-lg-3 clmargin">
<div class="form-group col-md-4 zeropadding div2adjustments">
@Html.LabelFor(m => m.StockDate, new { @class = "fieldtext" })
</div>
<div class="col-md-8 div2adjustments">
@ko.Html.TextBox(m => m.StockDate, new { @class = "form-control input-sm fieldtextinput ",
@id="stockdatepicker" })
</div>
</div>
</div>
@ko.Html.Button("Cancel", "sample1", "Inventory", new { value = Model.StockDate}, new { @class = "btn btn- primary maxheightbtn col-md-12", @id = "btn" })
}
Model Code-
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace OpManWeb.ViewModel.Inventory
{
public class TransactionHistory
{
[DisplayName("Stock Date")]
public string StockDate
{
get;
set;
}
}
}
Controller Code-
public ActionResult sample1(string value)
{
return Json(value);
}
I always get null for string value in controller..
Can anyone have faced such issue..?
Help..!!
Thanks In Advance..!!
c# asp.net-mvc razor knockout.js knockout-mvc
I am trying to send value of StockDate to Controller Method. I am getting Null.
http://knockoutmvc.com/ParametersToServer
as per above link if I pass static value like below.I can get value but when I use Model.Property I always get Null.
@ko.Html.Button("Inc 3", "Increment", "ParametersToServer", new { value = 3 })
Following is the code..
View Code-
@using PerpetuumSoft.Knockout
@model OpManWeb.ViewModel.Inventory.TransactionHistory
@{
var ko = Html.CreateKnockoutContext();
}
@{
ViewBag.Title = "Add Stock";
}
<script src="~/Scripts/perpetuum.knockout.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
@using (ko.Html.Form("SaveStock", "Inventory"))
{
<div class="row">
<div class="col-md-3 col-lg-3 clmargin">
<div class="form-group col-md-4 zeropadding div2adjustments">
@Html.LabelFor(m => m.StockDate, new { @class = "fieldtext" })
</div>
<div class="col-md-8 div2adjustments">
@ko.Html.TextBox(m => m.StockDate, new { @class = "form-control input-sm fieldtextinput ",
@id="stockdatepicker" })
</div>
</div>
</div>
@ko.Html.Button("Cancel", "sample1", "Inventory", new { value = Model.StockDate}, new { @class = "btn btn- primary maxheightbtn col-md-12", @id = "btn" })
}
Model Code-
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace OpManWeb.ViewModel.Inventory
{
public class TransactionHistory
{
[DisplayName("Stock Date")]
public string StockDate
{
get;
set;
}
}
}
Controller Code-
public ActionResult sample1(string value)
{
return Json(value);
}
I always get null for string value in controller..
Can anyone have faced such issue..?
Help..!!
Thanks In Advance..!!
c# asp.net-mvc razor knockout.js knockout-mvc
c# asp.net-mvc razor knockout.js knockout-mvc
edited Feb 26 '15 at 13:44
Aditya Raval
asked Feb 26 '15 at 12:27
Aditya RavalAditya Raval
387318
387318
Have you tried accessingmodel.StockDate
in your controller?
– Inspector Squirrel
Feb 26 '15 at 12:37
Yess I am getting null for string value inside my controller arguement..
– Aditya Raval
Feb 26 '15 at 12:40
That's because you aren't passing a key:value pair with the keyvalue
to the controller.
– Inspector Squirrel
Feb 26 '15 at 12:47
How can we achieve that...?Can you write answer for this question?
– Aditya Raval
Feb 26 '15 at 12:49
I know we can achieve that but i don't want to use the view model. I want to achieve this using parameter value which is passed into @ko.Html.Button..and inside controller its string value
– Aditya Raval
Feb 26 '15 at 12:55
|
show 1 more comment
Have you tried accessingmodel.StockDate
in your controller?
– Inspector Squirrel
Feb 26 '15 at 12:37
Yess I am getting null for string value inside my controller arguement..
– Aditya Raval
Feb 26 '15 at 12:40
That's because you aren't passing a key:value pair with the keyvalue
to the controller.
– Inspector Squirrel
Feb 26 '15 at 12:47
How can we achieve that...?Can you write answer for this question?
– Aditya Raval
Feb 26 '15 at 12:49
I know we can achieve that but i don't want to use the view model. I want to achieve this using parameter value which is passed into @ko.Html.Button..and inside controller its string value
– Aditya Raval
Feb 26 '15 at 12:55
Have you tried accessing
model.StockDate
in your controller?– Inspector Squirrel
Feb 26 '15 at 12:37
Have you tried accessing
model.StockDate
in your controller?– Inspector Squirrel
Feb 26 '15 at 12:37
Yess I am getting null for string value inside my controller arguement..
– Aditya Raval
Feb 26 '15 at 12:40
Yess I am getting null for string value inside my controller arguement..
– Aditya Raval
Feb 26 '15 at 12:40
That's because you aren't passing a key:value pair with the key
value
to the controller.– Inspector Squirrel
Feb 26 '15 at 12:47
That's because you aren't passing a key:value pair with the key
value
to the controller.– Inspector Squirrel
Feb 26 '15 at 12:47
How can we achieve that...?Can you write answer for this question?
– Aditya Raval
Feb 26 '15 at 12:49
How can we achieve that...?Can you write answer for this question?
– Aditya Raval
Feb 26 '15 at 12:49
I know we can achieve that but i don't want to use the view model. I want to achieve this using parameter value which is passed into @ko.Html.Button..and inside controller its string value
– Aditya Raval
Feb 26 '15 at 12:55
I know we can achieve that but i don't want to use the view model. I want to achieve this using parameter value which is passed into @ko.Html.Button..and inside controller its string value
– Aditya Raval
Feb 26 '15 at 12:55
|
show 1 more comment
1 Answer
1
active
oldest
votes
You can only send back extra static parameters with @ko.Html.Button
.
However you can get your whole client side model object (this is always sent by K-MVC) inside your controller action with adding a model
parameter to it.
So you can get the current model.StockDate
with modifying your controller action to:
public ActionResult sample1(TransactionHistory model)
{
return Json(model.StockDate);
}
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%2f28742465%2fhow-to-send-model-property-value-to-controller-method-in-k-mvc-using-ko-html-bu%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
You can only send back extra static parameters with @ko.Html.Button
.
However you can get your whole client side model object (this is always sent by K-MVC) inside your controller action with adding a model
parameter to it.
So you can get the current model.StockDate
with modifying your controller action to:
public ActionResult sample1(TransactionHistory model)
{
return Json(model.StockDate);
}
add a comment |
You can only send back extra static parameters with @ko.Html.Button
.
However you can get your whole client side model object (this is always sent by K-MVC) inside your controller action with adding a model
parameter to it.
So you can get the current model.StockDate
with modifying your controller action to:
public ActionResult sample1(TransactionHistory model)
{
return Json(model.StockDate);
}
add a comment |
You can only send back extra static parameters with @ko.Html.Button
.
However you can get your whole client side model object (this is always sent by K-MVC) inside your controller action with adding a model
parameter to it.
So you can get the current model.StockDate
with modifying your controller action to:
public ActionResult sample1(TransactionHistory model)
{
return Json(model.StockDate);
}
You can only send back extra static parameters with @ko.Html.Button
.
However you can get your whole client side model object (this is always sent by K-MVC) inside your controller action with adding a model
parameter to it.
So you can get the current model.StockDate
with modifying your controller action to:
public ActionResult sample1(TransactionHistory model)
{
return Json(model.StockDate);
}
answered Dec 31 '18 at 6:58
nemesvnemesv
123k13345323
123k13345323
add a comment |
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%2f28742465%2fhow-to-send-model-property-value-to-controller-method-in-k-mvc-using-ko-html-bu%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
Have you tried accessing
model.StockDate
in your controller?– Inspector Squirrel
Feb 26 '15 at 12:37
Yess I am getting null for string value inside my controller arguement..
– Aditya Raval
Feb 26 '15 at 12:40
That's because you aren't passing a key:value pair with the key
value
to the controller.– Inspector Squirrel
Feb 26 '15 at 12:47
How can we achieve that...?Can you write answer for this question?
– Aditya Raval
Feb 26 '15 at 12:49
I know we can achieve that but i don't want to use the view model. I want to achieve this using parameter value which is passed into @ko.Html.Button..and inside controller its string value
– Aditya Raval
Feb 26 '15 at 12:55