JQuery dropdown click function not working in asp.net mvc - javascript

I'm new to jQuery, here when I click the department code dropdown list then department name want to come inside the input field as well as I used jQuery function for that. the problem is to the department name didn't come while click the dropdown. I couldn't find out my mistake in my jQuery code, if anyone find out that it will be most helpful for me. Below, I saw my necessary code only
1.Create.cshtml
<tr class="spaceUnder">
<td>
<label for="departmentId">DepartmentCode</label>
</td>
<td>
<select name="departmentId" id="departmentId">
<option value="">Select...</option>
#foreach (var department in ViewBag.Departments)
{
<option value="#department.ID">#department.Code</option>
}
</select>
</td>
</tr>
<tr class="spaceUnder">
<td><label for="DepartmentName">DepName</label></td>
<td>
<input type="text" readonly="readonly" name="DepartmentName" id="DepartmentName" data-val="true">
</td>
</tr>
<script>
$(document).ready(function()
{
$('#departmentId').change(function ()
{
var DepId = $('#departmentId').val();
var json = { DepartmentId: DepId };
$.ajax(
{
type: "POST",
url: "/TeacherCourseAssign/GetDepartmentByDepartmentId",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(json),
success: function
(data) {
$('#DepartmentName').val(data.Name);
}
}
);
}
);
}
);
</script>
2.SubjectController.cs
public ActionResult Index()
{
var subjects = db.Subjects.Include(s => s.Department);
return View(subjects.ToList());
}
3.TeacherCourseAssignController.cs
public JsonResult GetDepartmentByDepartmentId(int departmentId)
{
List<Department> departments = aDepartmentManager.GetAllDepartments();
var department = departments.Find(a => a.ID == departmentId);
return Json(department);
}
4.DepartmentManager.cs
public List<Models.Department> GetAllDepartments()
{
return aDepartmentGateway.GetAllDepartment();
}
5.DepartmentGateway.cs
public List<Department> GetAllDepartment()
{
SqlConnection connection = new SqlConnection(connectionString);
string Query = "SELECT * FROM Departments ";
SqlCommand command = new SqlCommand(Query, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
List<Department> departments=new List<Department>();
while (reader.Read())
{
Department department = new Department()
{
ID=(int)reader["ID"],
Name = reader["Name"].ToString(),
Code=reader["Code"].ToString()
};
departments.Add(department);
}
reader.Close();
connection.Close();
return departments;
}
6.Subject.cs ( model )
public class Subject
{
public int SubjectID { get; set; }
[DisplayName("Department")]
public int? DepartmentId { get; set; }
[ForeignKey("DepartmentId")]
public virtual Department Department { get; set; }
[DisplayName("DepName")]
public string DepartmentName { get; set; }
}

i think, you made several mistake while writing the JQuery code.Try this, it might work for you.
#section scripts
{
<script>
$(document).ready(function()
{
$("#departmentId").change(function ()
{
var DepId = $("#departmentId").val();
var json = { DepartmentId: DepId };
$.ajax(
{
type: "POST",
url: '/TeacherCourseAssign/GetDepartmentByDepartmentId',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(json),
success: function
(data) {
$("#DepartmentName").val(data.Name);
}
}
);
}
);
}
);
</script>
}
then After try to Debugging JavaScript in your browser ,here you want to put the breakpoints appropriate place and find your solution as well.(More Details Debugging JavaScript in chrome.LinkHere)

Related

Send data using JQuery (redirectPost) and Net 6

I am migrating an application from the .Net Framework to .Net 6
But I have a problem, when I click "Download Report" I send data from the view to the controller, but "filterOptions" is always null in the controller.
I show the code below.
<button id="btnReport">Download Report</button>
<div class="form-group">
<select class="form-control select2" id="selectFilter" multiple="multiple">
<option value="OK">OK</option>
<option value="ERROR">ERROR</option>
</select>
</div>
<script>
var filterOptions = {
Options: [],
Data: '',
}
function AddFilters(options, data) {
filterOptions.Options = options;
filterOptions.Data = data
}
//selectFilter: Ok, Error
'#btnReport': function (e) {
AddFilters(
$('#selectFilter').select2('data').map((x) => x.id)
, $('#txtData').val()
);
var startDate = moment($('#rStartDate').datepicker('getDate'));
var endDate = moment($('#rEndDate').datepicker('getDate'));
return $.redirectPost('#Url.Action("MyMethod", "Controller")',
{
startDate.toISOString(),
endDate.toISOString(),
filterOptions
});
}
</script>
This is my controller.
[HttpPost]
public ActionResult MyMethod(DateTime? startDate,
DateTime? endDate,
Filters filterOptions)
{
/*More code*/
}
public class Filters
{
public IEnumerable<string> Options { get; set; }
public string Data { get; set; }
}
I do not understand what the problem is.
I hope you can help me.
Thank you
Are you considering using ajax to make the call?
$.ajax({
type: 'post',
url: '#Url.Action("MyMethod", "Controller")',
data: { startDate, endDate, filterOptions },
success: function (result) {
//...
},
error: function (error){
}
});

Unable to bind html table data to mvc controller Model

I have this model
public class Model
{
public string itemlineId { get; set; }
public string shipmentID { get; set; }
public string containerID { get; set; }
public string containerType { get; set; }
}
I have a dynamic html table, what im trying to do is to post table data through ajax,and send it to the controller
$("body").on("click", "#btnSave", function () {
//Loop through the Table rows and build a JSON array.
var itemlists= new Array();
$("#tblAttachShip TBODY TR").each(function () {
var row = $(this);
var itemList = {};
itemList.itemlineId = row.find("TD").eq(0).html();
itemList.shipmentID = document.getElementById("txtShipmentID").value
itemList.containerID = row.find("TD").eq(1).html();
itemList.containerType = row.find("TD").eq(2).html();
itemlists.push(itemList);
});
//Send the JSON array to Controller using AJAX.
$.ajax({
type: "POST",
url: "/Project/Create",
data: JSON.stringify({ Model : Itemslists}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
alert(r + " record(s) inserted.");
}
});
});
so far all okay, when I try to read the post request in the browser I can see that the request has the correct data as json format
Model: [{itemlineId: "aa", shipmentID: "a", containerID: "aa", containerType: "aa"}]}
however when I check the controller the list doesn't contain any elements, and no values has been binded, I checked several posts but I can't figure ouut what I did wrong to bind the json data to the model in the controller
[HttpPost]
public JsonResult Create(List<Model> Model)
{
return Json("Success");
}
EDIT
I think we both jumped the gun a bit there. I did some digging and it looks like the JSON.stringify is actually going to be necessary because of the way that ajax posts the data; I think your issue might actually be with the javascript. When I copied your code, there were errors. I am running this right now which is working. Assuming your posted code was copy and pasted, this:
data: JSON.stringify({ Model : Itemslists}),
should be
data: JSON.stringify({ Model : itemlists}),
Looks like it was just a typo with the name of the array.
Working code:
#{
ViewBag.Title = "Home Page";
}
<script src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<script type="text/javascript">
$("body").on("click", "#btnSave", function () {
//Loop through the Table rows and build a JSON array.
var itemlists = new Array();
$("#tblAttachShip TBODY TR").each(function () {
var row = $(this);
var itemList = {};
itemList.itemlineId = row.find("TD").eq(0).html();
itemList.shipmentID = document.getElementById("txtShipmentID").value
itemList.containerID = row.find("TD").eq(1).html();
itemList.containerType = row.find("TD").eq(2).html();
itemlists.push(itemList);
});
//Send the JSON array to Controller using AJAX.
$.ajax({
url: './Home/Create',
type: 'POST',
data: JSON.stringify({ Model: itemlists }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
alert(r + " record(s) inserted.");
},
error: function (r) {
alert(JSON.stringify(r));
}
});
});
</script>
<input type="text" id="txtShipmentID" />
<table id="tblAttachShip">
<tbody>
<tr>
<td>aaa</td>
<td>aa</td>
<td>a</td>
</tr>
<tr>
<td>bbb</td>
<td>bb</td>
<td>b</td>
</tr>
</tbody>
</table>
<button id="btnSave">Save</button>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication1.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
[HttpPost]
public JsonResult Create(List<Model> Model)
{
return Json(new { Message = "Success" });
}
}
public class Model
{
public string itemlineId { get; set; }
public string shipmentID { get; set; }
public string containerID { get; set; }
public string containerType { get; set; }
}
}
You are stringifying your object:
data: JSON.stringify({ Model : Itemslists}),
So you are passing a string into your controller, when your controller expects a List.
Off the top of my head i'd say try just passing the object e.g.
data: Itemslists,
Or if there is a reason that you need to pass it as a string. Change your controller to receive a string and then deserialize it:
(List<Model>)serializer.Deserialize(jsonString, typeof(List<Model>);

Trouble with autocomplete

I have a functional autocomplete, however when I fill in the data it shows me the name to select, but when I select it ... it stores the ID of that name that I selected.
In the database the value to save is the ID of that name selected, but is there any way it can fill me in with the name and store the ID in the database?
for example, I selected a name, but it shows me the ID and not the name, as shown in the image. Is it possible that he shows me the name and just keeps the ID?
Model
public partial class Filho
{
public int ID_Filho { get; set; }
public int ID_Utilizador { get; set; }
public string Nome { get; set; }
public string Morada { get; set; }
public System.DateTime DataNascimento { get; set; }
public System.DateTime DataRegisto { get; set; }
public int ID_Sala { get; set; }
public virtual Utilizador Utilizador { get; set; }
public virtual Sala Sala { get; set; }
}
Controller
public JsonResult AutoComplete(string prefix)
{
ClassEntities entities = new ClassEntities();
var pais = (from Utilizador in entities.Utilizador
where Utilizador.NomeUtilizador.StartsWith(prefix)
select new
{
label = Utilizador.NomeUtilizador,
val = Utilizador.ID_Utilizador
}).ToList();
return Json(pais);
}
HTML
<div class="wrap-input100 rs1-wrap-input100 validate-input">
<span class="label-input100">NAME</span>
<input class="input100" type="text" id="txtUtilizador" name="ID_Utilizador">
<span class="focus-input100"></span>
</div>
JavaScript
<script type="text/javascript">
$("#txtUtilizador").autocomplete({
source: function (request, response) {
$.ajax(
{
url: '/Filhos/AutoComplete/',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
cache: false,
success: function (data) {
response($.map(data, function (item) {
return {
label: item.label,
value: item.val,
};
}))
}
})
},
error: function (error) {
alert(error);
}
});
</script>
Method
public ActionResult Create()
{
ViewBag.ID_Utilizador = new SelectList(db.Utilizador, "ID_Utilizador", "NomeUtilizador");
ViewBag.ID_Sala = new SelectList(db.Sala, "ID_Sala", "NomeSala");
return View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "ID_Filho,ID_Utilizador,Nome,Morada,DataNascimento,DataRegisto,ID_Sala")] Filho filho)
{
if (ModelState.IsValid)
{
db.Filho.Add(filho);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.ID_Utilizador = new SelectList(db.Utilizador, "ID_Utilizador", "NomeUtilizador", filho.ID_Utilizador);
ViewBag.ID_Sala = new SelectList(db.Sala, "ID_Sala", "NomeSala", filho.ID_Sala);
return View(filho);
}
You need add a hidden field with name to keep value when submit form.
<input type="hidden" name="ID_Utilizador"/>
Implement select method, comment out custom mapping
select: function (event, ui) {
event.preventDefault();
$(this).val(ui.item.label);
$("[name='ID_Utilizador']").val(ui.item.value);
}
This is html for page
<div class="wrap-input100 rs1-wrap-input100 validate-input">
<span class="label-input100">NAME</span>
<input class="input100" type="text" id="txtUtilizador">
<input type="hidden" name="ID_Utilizador"/>
<span class="focus-input100"></span>
</div>
<script type="text/javascript">
$("#txtUtilizador").autocomplete({
source: function (request, response) {
$.ajax(
{
url: '/Filhos/AutoComplete/',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
cache: false,
success: function (data) {
//response($.map(data, function (item) {
// return {
// label: item.label,
// value: item.val,
// id : item.val
// };
//}))
response(data);
}
})
},
select: function (event, ui) {
event.preventDefault();
$(this).val(ui.item.label);
$("[name='ID_Utilizador']").val(ui.item.value);
},
error: function (error) {
alert(error);
}
});

Form is not Submitting any Value using Asp.Net MVC

In Model:
public int TeacherCourseAssignId { set; get; }
public int TeacherID { set; get; }
public decimal TeacherRemainingCredit { set; get; }
public int CourseId { set; get; }
public string CourseName { set; get; }
public decimal CourseCredit { set; get; }
In controller:
[HttpPost]
public ActionResult TeacherCourseAssign(int departmentId, int teacherId, int courseId)
{
ViewBag.Departments = GetDepartments();
return View();
}
public ActionResult SaveTeacherCourseAssign(TeacherCourseAssign teacherCourseAssign)
{
ViewBag.Departments = GetDepartments();
ViewBag.Message = teacherCourseAssignManager.Save(teacherCourseAssign);
ModelState.Clear();
return View();
}
public JsonResult SaveTeacheCourseAssign(TeacherCourseAssign teacherCourseAssign)
{
//Code
return Json(true, JsonRequestBehavior.AllowGet);
}
public JsonResult GetTeachersByDepartmentId(int deptId)
{
var teachers = GetTeacher();
var teacherList = teachers.Where(a => a.DepartmentId == deptId).ToList();
return Json(teacherList, JsonRequestBehavior.AllowGet);
}
public JsonResult GetCoursesByDepartmentId(int deptId)
{
var courses = GetCourses();
var courseList = courses.Where(a => a.DepartmentId == deptId).ToList();
return Json(courseList, JsonRequestBehavior.AllowGet);
}
public JsonResult GetTeachersInfoByTeacherId(int teacherId)
{
var teachers = GetTeacher();
var teacherInfo = teachers.Where(t => t.TeacherID == teacherId).ToList();
return Json(teacherInfo, JsonRequestBehavior.AllowGet);
}
public JsonResult GetCoursesInfoByCourseId(int courseId)
{
var courses = GetCourses();
var courseList = courses.Where(c => c.CourseId == courseId).ToList();
return Json(courseList, JsonRequestBehavior.AllowGet);
}
In View:
#model Last.Models.TeacherCourseAssign
#{
ViewBag.Title = "Teacher Course Assign";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Teacher Course Assign</h2>
<form method="POST" id="myForm">
<table>
<tr>
<td>
<label for="departmentId">Select Department</label>
</td>
<td>
<select name="departmentId" id="departmentId">
<option value="">Select...</option>
#foreach (var department in ViewBag.Departments)
{
<option value="#department.DeptId">#department.DeptName</option>
}
</select>
</td>
</tr>
<tr>
<td><label for="teacherId">Teacher</label></td>
<td>
<select name="teacherId" id="teacherId"></select>
</td>
</tr>
<tr>
<td>#Html.LabelFor(m => m.CreditToBeTaken)</td>
<td>#Html.TextBoxFor(m => m.CreditToBeTaken)</td>
</tr>
<tr>
<td>#Html.LabelFor(r => r.TeacherRemainingCredit)</td>
<td>
#Html.TextBoxFor(r => r.TeacherRemainingCredit)
</td>
</tr>
<tr>
<td><label for="courseId"></label></td>
<td>
<select name="courseId" id="courseId"></select>
</td>
</tr>
<tr>
<td>#Html.LabelFor(n => n.CourseName)</td>
<td>
#Html.TextBoxFor(n => n.CourseName)
</td>
</tr>
<tr>
<td>#Html.LabelFor(c => c.CourseCredit)</td>
<td>
#Html.TextBoxFor(c => c.CourseCredit)
<br>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" id="Submit" value="Assign" class="btn btn-default" /></td>
</tr>
</table>
</form>
#section scripts
{
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function() {
$("#departmentId").change(function() {
var dept = $("#departmentId").val();
$("#teacherId").empty();
$("#courseId").empty();
var json = { deptId: dept };
//$("#teacherId").append('<option value="">Select</option>');
$.ajax({
type: "POST",
url: '#Url.Action("GetTeachersByDepartmentId", "TeacherCourseAssign")',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(json),
success: function(data) {
$("#teacherId").append('<option value="">Select</option>');
$.each(data, function(key, value) {
$("#teacherId").append('<option value=' + value.TeacherID + '>' + value.TeacherName + '</option>');
});
}
});
// $("#courseId").append('<option value="">Select</option>');
$.ajax({
type: "POST",
url: '#Url.Action("GetCoursesByDepartmentId", "TeacherCourseAssign")',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(json),
success: function(data) {
$("#courseId").append('<option value="">Select</option>');
$.each(data, function(key, value) {
$("#courseId").append('<option value=' + value.CourseId + '>' + value.CourseCode + '</option>');
});
}
});
});
$("#teacherId").change(function() {
var tech = $("#teacherId").val();
var json = { teacherId: tech };
$.ajax({
type: "POST",
url: '#Url.Action("GetTeachersInfoByTeacherId", "TeacherCourseAssign")',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(json),
success: function(data) {
$.each(data, function(key, value) {
$("#CreditToBeTaken").val(value.CreditToBeTaken);
$("#TeacherRemainingCredit").val(value.CreditToBeTaken);
});
}
});
});
$("#courseId").change(function() {
var tech = $("#courseId").val();
var json = { courseId: tech };
$.ajax({
type: "POST",
url: '#Url.Action("GetCoursesInfoByCourseId", "TeacherCourseAssign")',
contentType: "application/json; charset=utf-8",
data: JSON.stringify(json),
success: function(data) {
$.each(data, function(key, value) {
$("#courseName").val(value.CourseName);
$("#CourseCredit").val(value.Credit);
});
}
});
});
});
</script>
}
My Cascading DropDown for department, course and teacher Info is working fine. but when I click on submit. it is not submitting any value to my post controller SaveTeacherCourseAssign(). want to know am i submitting my model in a wrong way?
Are you able to hit the controller at all? By default, all controllers actions listen to GET requests, so if you can't hit it, you would have to decorate it with [HttpPost] in order to hit it.
Also, I don't see any ajax request that's targeting it. Unless it's the form, at which point you might want to explicitly put an action attribute on it if the page/view name is not the same.
If you're in fact hitting a breakpoint when you submit, are you just getting a null object?
Alright, you have your form element but it doesn't have any action property. You have to add it like:
<form method="POST" id="myForm"
action="#Url.Action("your_action_method_name" , "your_controller_name")" >
I think this is what you are missing.

X-editable with ASP MVC View, how to get the submitted form POST action to the controller

I am using X-Editable Plugin to capture user input, and performing submission to server. I'm getting an error on submission, what should I change to get the x-editable data working with the form.
Do I change the Controller (signature or attribute?), or the
Javascript AJAX arguments to get past the submission?
for some scenarios, how do I autodetect the change in the inline, X-editable texbox to
perform a post right away, when user leaves the box.
What would I need to change in the Javascript to make it work with a partial view
Would it enhance my solution if I were to encapsulate the HTML in a form, and use the
user button submission
Javascript:
$('#Application').editable({
url: function (params) {
return $.ajax({
url: 'Application/Create',
type: "POST",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(params),
dataType: 'json',
async: true,
success: function (response) {
alert("Success");
},
error: function () {
alert("Error in Ajax");
}
});
}
});
HTML:
<!-- language: lang-html -->
<!-- language: C# -->
[HttpPost]
//[Authorize]
public ActionResult Create(String params)
{
var = params;
//Deserialize and Get params here and create application objeci
Return View();
}
This seemed to work for me ...
Javascript ...
$('#searchresult a').editable({
url: function (params) {
var requestData = '';
if (params.name == 'employeeno')
requestData = { UserName: params.pk, EmployeeNo: params.value }
else
return; //perform no update
return $.ajax({
cache: false,
async: true,
type: 'POST',
data: requestData,
url: 'EASMUser/UpdateAccountProperty',
beforeSend: showWaitCursor('Updating EASM Account ...'),
success: function (response) {
alert("Success");
},
error: function (data) {
debugger;
alert(data);
}
});
}
}
);
Model ...
public class EASMUserViewModel
{
public string UserName { get; set; }
public string EmployeeNo { get; set; }
public string Password { get; set; }
public List<Entity> Entities {get; set;}
/// <summary>
/// Helper method to convert to string
/// </summary>
/// <returns></returns>
public string EntitiesToString()
{
if (Entities == null || Entities.Count == 0)
return string.Empty;
StringBuilder sb = new StringBuilder();
foreach( Entity pe in Entities)
{
string target = sb.Length > 0 ? ",{0}": "{0}";
sb.AppendFormat(target, Convert.ToInt32(pe));
}
return sb.ToString();
}
}
Controller Method ...
[HttpPost]
public ActionResult UpdateAccountProperty(EASMUserViewModel easmuser )
{
try
{
//using a grid with multiple x-editable controls
if (!string.IsNullOrEmpty(easmuser.EmployeeNo))
{
//Updating Employeeno
//TODO: update db
}
else if (!string.IsNullOrEmpty(easmuser.Password))
{
//Updating password
//TODO: update db
}
return Content(string.Format("[{0}] updated successfully.", easmuser.UserName));
}
catch (Exception exc)
{
//TODO: Add logging
return ThrowJsonError(exc);
}
}
Mark up (creating a table body with multiple x-editable controls) ...
<tbody>
#foreach (var item in Model)
{
<tr id="#item.UserName">
<td>#item.UserName</td>
<td>#item.EmployeeNo</td>
<td><a href="#" id="password" data-type="text" data-title="Enter Password" data-pk="#item.UserName" >#item.Password</a></td>
<td><a href="#" id="entities" data-type="checklist"
data-pk="#item.UserName"
data-source="[{ value: 1, text: 'Entity1' },{ value: 2, text: 'Entity2' },{ value: 3, text: 'Entity3' }, { value: 4, text: 'Entity4' },{ value: 6, text: 'Entity5' }]"
data-title="Select Entities"
data-value="#item.EntitiesToString()"
>
</a>
</td>
<td>
<button class="btn btn-xs btn-danger" id="#item.UserName"
data-toggle="tooltip" data-placement="left"
onclick="deleteEASMUserAccount('#item.UserName');"
title="Delete #item.UserName" >
<i class="fa fa-times"></i>
</button>
</td>
</tr>
}
</tbody>
I know this is way old but you might find it useful if you've got similar question
VIEW
$('#url').editable({
url: '#Url.Action("EditProfile","Company")',
type: 'text',
pk: #Model.ID,
name: 'url',
title: 'Enter URL'
});
CONTROLLER
public ActionResult EditProfile(FormCollection fc)
{
try
{
if (ModelState.IsValid)
{
Customer cust = new Customer();
cust.ID = Convert.ToInt32(fc["pk"]);
cust.DATE_MODIFIED = DateTime.Now;
User user = (User)Session["currentuser"];
cust.MODIFIEDBY = user != null ? user.ID : 0 ;
//set values based on the x-editable complement from view
if (fc["name"] == "companyname") cust.BUSINESSNAME = fc["value"];
if (fc["name"] == "motto") cust.MOTTO = fc["value"];
if (fc["name"] == "phone") cust.CONTACT_PHONE1 = fc["value"];
if (fc["name"] == "phone1") cust.CONTACT_PHONE2 = fc["value"];
if (fc["name"] == "url") cust.CONTACT_URL = fc["value"];
if (fc["name"] == "about") cust.ABOUT = fc["value"];
//update Customer Table
new CustomerRepo().UpdateCustomer(cust);
//return 200 OK as expected by x-editable
return new JsonResult();
}
// Response.StatusCode = (int)HttpStatusCode.OK;
// Response.SuppressFormsAuthenticationRedirect = true;
return Json(new { status = "error", message = "Update Failed. Please try again later" });
}
catch(Exception ex)
{
// Response.StatusCode = (int)HttpStatusCode.OK;
// Response.SuppressFormsAuthenticationRedirect = true;
return Json(new { status="error", message = "Update Failed. Please try again later" });
}
}

Categories

Resources