我使用MVC ASP。爲什麼當我打電話時我的操作方法沒有觸發?
這裏是JavaScript對象,我發送到動作方法:
var layerProp = {VectorLayerId:5, FieldName: "someText", FieldType:"someText", FieldValue: "someText", Required:false }
這裏是我的ajax功能:
function saveProperty(layerProp, callback, error) {
return $.ajax({
url: '/Mobile/LayerProperty/SaveProperty',
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: { layerProp: layerProp },
success: callback,
error: error
});
}
這裏是控制我的行動類型:
[HttpPost]
public JsonResult SaveProperty(GeomindMobile.Core.Data.VectorLayers_Fields layerProp)
{
try
{
var q = _repository.SaveProperty(layerProp);
return Json(new { Result = "OK" }, JsonRequestBehavior.DenyGet);
}
catch (Exception ex)
{
return Json(new { Result = "Bad", ex.Message });
}
}
這是我的實體,類型defenition:
public partial class VectorLayers_Fields
{
public VectorLayers_Fields()
{
this.VectorLayer_FieldsValue = new HashSet<VectorLayer_FieldsValue>();
}
public int Id { get; set; }
public int VectorLayerId { get; set; }
public string FieldName { get; set; }
public string FieldType { get; set; }
public string FieldValue { get; set; }
public bool Required { get; set; }
public virtual ICollection<VectorLayer_FieldsValue> VectorLayer_FieldsValue { get; set; }
}
任何想法,爲什麼當我後我的數據到控制器我得到這個錯誤:
無法加載資源:服務器迴應500(內部服務器錯誤)的狀態
UPDATE:
這裏是massege有關錯誤,我在拉琴得到:
[ArgumentException: Invalid JSON primitive: layerProp.]
System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject() +707
System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth) +333
System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer) +110
System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) +46
System.Web.Mvc.JsonValueProviderFactory.GetDeserializedObject(ControllerContext controllerContext) +230
System.Web.Mvc.JsonValueProviderFactory.GetValueProvider(ControllerContext controllerContext) +24
System.Web.Mvc.<>c__DisplayClassc.<GetValueProvider>b__7(ValueProviderFactory factory) +45
System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +223
System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +263
System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +504
System.Linq.Enumerable.ToList(IEnumerable`1 source) +70
System.Web.Mvc.ValueProviderFactoryCollection.GetValueProvider(ControllerContext controllerContext) +361
System.Web.Mvc.ControllerBase.get_ValueProvider() +50
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +77
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +143
System.Web.Mvc.Async.<>c__DisplayClass25.<BeginInvokeAction>b__1e(AsyncCallback asyncCallback, Object asyncState) +744
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +164
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +380
System.Web.Mvc.<>c__DisplayClass1d.<BeginExecuteCore>b__17(AsyncCallback asyncCallback, Object asyncState) +44
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +164
System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +532
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +164
System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +416
System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__2(AsyncCallback asyncCallback, Object asyncState) +120
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +164
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +309
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +1028
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +134
你看過什麼異常堆棧跟蹤是服務器端? 您是否嘗試在操作方法中放置斷點以查看它是否命中? –
什麼是500的描述? – Ssheverdin
@MartinBlore是的,我試過了,沒有達到行動方法 – Michael