即時通訊發佈包含文件和html數據加上函數來獲取地理編碼的形式,但控制器只從ajax文件中獲取數據,但不是文件, 我假設它有是與事實按鈕張貼,但我不知道,ajax不會發布文件到控制器mvc
@using (Html.BeginForm("Create", "lecture", FormMethod.Post, new { enctype = "multipart/form-data", id = "RestoForm" }))
{
//values has remove for clear
<div class="form-group">
@Html.LabelFor(f => f.RImage) <i class="glyphicon glyphicon-folder-open"></i>
<input type="file" name="RImage" class="btn btn-default btn-sm btn-google btn-group-justified hvr-shadow " />
</div>
<input type="button" class="btn btn-primary btn-lg" onclick="GetLocation()" value="Finish" />
}
@section scripts
{
<script type="text/javascript">
function GetLocation() {
var geocoder = new window.google.maps.Geocoder();
var Street = document.getElementById('txtAddress').value;
var City = document.getElementById('txtCity').value;
var address = City + Street;
console.log(address);
var labelLat = document.getElementById('Latitude');
var labellong = document.getElementById('longitude');
geocoder.geocode({ 'address': address },
function (results, status) {
if (status == window.google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
console.log("Latitude: " + latitude + "\nLongitude: " + longitude); //Ok.
labelLat.value = latitude; //Ok.
labellong.value = longitude;
$.ajax({
url: 'Create',
type: 'POST',
data: $('#RestoForm').serialize(),
datetype: "html",
success: function (data) {
$('#RestoForm').html(data);
}
});
error: function e(xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
}
});
};
</script>
controlle`
[Authorize, HttpPost, ValidateAntiForgeryToken]
public ActionResult Create(LectureFormViewModel viewModel) // RImage =Null
{`
'datetype'錯字錯誤?它應該是'datatype'。並且使用'FormData'不僅是'Serialize' –
Uncaught TypeError:$(...)。FormData不是函數(...)data:$('#RestoForm')。FormData(), dattype:「html」, –
你可以顯示LectureFormViewModel嗎? –