0

I want to pass element from model to "setlaneOnFloor" method in .cshtml but error said they not exist.

<script>
function setlane(){
let floor = document.getElementById("floor");
let lane = document.getElementById("lane");
@Model.setlaneOnFloor(floor,lane)
}

</script>
[WebMethod]
public string setlaneOnFloor(int floor, int num)
{
return cmd.setlaneinsection(floor, num);
}

i also try this but i flews like I'm do something wrong.

<script>
function setlane(){
var data = { floor: document.getElementById("floor"), num: document.getElementById("lane") };
$.ajax({
type: "POST",
url: '\<%= ResolveUrl("\~/setlaneOnFloor") %\>',
data: JSON.stringify(data),
contentType: "application/json",
success: function (msg) {
$("#txtStartDate").val(msg.d);

}
});
}
</script>

I want to pass the element something like this @Model.setlaneOnFloor(5,6)\

5
  • 1
    you wanna pass data from backend to javascript method directly? Commented Sep 21, 2023 at 5:32
  • What is your project type that have WebMethod attribute ? what is your framework? Commented Sep 21, 2023 at 22:34
  • for @XinranShen ,I want to pass data from frontend [HTML, JS] to backend [C#] Commented Sep 22, 2023 at 1:42
  • for @mamad2559 it's asp.net web application.I add WebMethod because i try to do ajax Commented Sep 22, 2023 at 1:48
  • You can refer to this link. Commented Sep 22, 2023 at 6:22

0

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.