If you want to know how to get the localstorage and post it to asp.net core backend.
I suggest you could try to use jquery to achieve it ,you could use localStorage.setItem(key,value);
to set localStorage.getItem(key);
to get, then you could use ajax to post request to backend.
More details, you could refer to below codes:
Client-side set and get localstorage by using ajax:
<input name="SetValue" id="SetValue" value="SetValue" type="button" />
<br />
<input name="SendValue" id="SendValue" value="SendValue" type="button" />
@section scripts{
<script>
$(function () {
$("#SetValue").click(function () {
localStorage.setItem("test", "value")
});
$("#SendValue").click(function () {
var str1 = localStorage.getItem("test");
$.ajax({
type: "POST",
data: JSON.stringify(str1),
contentType: "application/json; charset=utf-8",
dataType: "json",
url: '/home/Myaction',
success: function (data) {
},
error: function (xhr) {
console.log(xhr.responseText);
alert("Error has occurred..");
}
});
});
});
</script>
}
MVC controller:
[HttpPost]
public ActionResult MyAction([FromBody]string str1)
{
return View();
// code here
}
Result:
