Answer the question
In order to leave comments, you need to log in
How to get data from form to controller?
I connected this script
www.codeproject.com/Tips/503495/Simple-rating-cont... The
question is how to get data from it to the controller, it is written that
Request.Form (ASP or ASP.NET), but wrapping in Http.BeginForm for some reason did not receive data in the controller.
Maybe someone will help by writing a controller prototype to which data should come
my code:
@using (Html.BeginForm("SetRating", "Album", FormMethod.Post))
{
<input type="text" class="rating rating10" value="3" name="rating"/>
}
[HttpPost]
public void SetRating(int rating)
{
throw new Exception();
}
(function ($)
{
$.fn.rating = function (options)
{
var settings = $.extend(
{
rateEnd: function (value) { }
}, options);
function setRating(e, ul)
{
var i = parseInt(e.val());
if (!i) { i = 0; }
ul.find('a').removeAttr('class');
ul.find('a:lt(' + i + ')').attr('class', 'full');
}
this.each(function ()
{
var e = $(this);
var c = parseInt(e.attr("class").match(/rating\d+/)[0].replace('rating', ''));
var ul = $('<ul class="rating"></ul>').insertAfter(e).width(c * 20 + 'px');
if (c > 0)
{
for (k = 0; k < c; k++)
{
ul.append('<li><a href="javascript:void(0);" title="' + (k + 1) + '">' + (k + 1) + '</a></li>')
}
}
if (e.prop('readonly'))
{
var i = parseInt(e.val());
if (!i) { i = 0; }
ul.find('a').attr('title', i + ' / ' + c);
}
else
{
ul.find('a').each(function (index, link)
{
var link = $(link);
link.hover(function ()
{
ul.find('a').removeAttr('class');
ul.find('a:lt(' + (index + 1) + ')').attr('class', 'hover');
}, function ()
{
setRating(e, ul);
});
link.click(function ()
{
e.val(index + 1);
setRating(e, ul);
settings.rateEnd(index + 1);
});
});
}
setRating(e, ul);
e.hide();
});
return this;
}
})(jQuery);
Answer the question
In order to leave comments, you need to log in
First, the form does not show an element with the submit type. How do you send it?
Secondly, when submitting the form, look at what is actually sent via HttpPost to the controller. Through the tools in the browser via F12.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question