Hello I am trying to write a save function in my asp.net mvc application. It works fine, but I had to change
public ActionResult Index(List<Doctor> drnos, int? page)
to
public ActionResult save(List<Doctor> drnos, int? page)
because the function was being called when the index loaded. The problem is that it does not like that I am referencing "save" instead of "Index". I already have an Index function that does multiple things including the implementation of a search bar. I do not want the save function to be called every time the index is loaded. What am I doing wrong in my "save" function? Thanks!
drnosController
public ActionResult save()
{
return View();
}
[HttpPost]
public ActionResult save(List<Doctor> drnos, int? page)
{
System.Diagnostics.Debug.WriteLine("Save Called");
DrNOSv2Entities db = new DrNOSv2Entities();
foreach (Doctor doc in drnos)
{
Doctor existing = db.Doctors.Find(doc.RVH_ID_);
if (existing != null)
{
System.Diagnostics.Debug.WriteLine("passed if");
existing.AdmPriv = doc.AdmPriv;
existing.QCPR = doc.QCPR;
existing.Keane = doc.Keane;
existing.Orsos = doc.Orsos;
existing.Soft = doc.Soft;
existing.C3M = doc.C3M;
}
}
db.SaveChanges();
int pageSize = 100;
int pageNumber = (page ?? 1);
return View(drnos.ToPagedList(pageNumber, pageSize));
}
Index.cshtml
@using (Html.BeginForm("save", "drnos", FormMethod.Post, new { id = "doctorform" }))
{
for (int i = 0; i < Model.Count; i++)
{
<tr>
<td>
@Model[i].RVH_ID_
@Html.HiddenFor(m => m[i].RVH_ID_)
</td>
<td>
@Model[i].Last_Name
@Html.HiddenFor(m => m[i].Last_Name)
</td>
<td>
@Model[i].First_Name
@Html.HiddenFor(m => m[i].First_Name)
</td>
<td>
@Model[i].Middle_Name
@Html.HiddenFor(m => m[i].Middle_Name)
</td>
<td>
@Model[i].Degree1
@Html.HiddenFor(m => m[i].Degree1)
</td>
<td>
@Model[i].Group
@Html.HiddenFor(m => m[i].Group)
</td>
<td>
@Html.CheckBoxFor(m => m[i].AdmPriv)
</td>
<td>
@Html.CheckBoxFor(m => m[i].QCPR)
</td>
<td>
@Html.CheckBoxFor(m => m[i].Keane)
</td>
<td>
@Html.CheckBoxFor(m => m[i].Orsos)
</td>
<td>
@Html.CheckBoxFor(m => m[i].Soft)
</td>
<td>
@Html.CheckBoxFor(m => m[i].C3M)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = Model[@i].RVH_ID_ })
@Html.ActionLink("Details", "Details", new { id = Model[@i].RVH_ID_ })
</td>
</tr>
}
}
</table>
Doctor.cs
namespace drnosv6.Models
{
using System;
using System.Collections.Generic;
public partial class Doctor
{
public int RVH_ID_ { get; set; }
public string NPI { get; set; }
public bool On_Staff { get; set; }
public bool AdmPriv { get; set; }
public bool Inactive { get; set; }
public string License_Verification_Date { get; set; }
public string Last_Name { get; set; }
public string First_Name { get; set; }
public string Middle_Name { get; set; }
public string Group { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Zip { get; set; }
public string State { get; set; }
public string Telephone { get; set; }
public string Fax { get; set; }
public string Phys_Spclty { get; set; }
public string License_ { get; set; }
public string UPIN { get; set; }
public bool QCPR { get; set; }
public bool Keane { get; set; }
public bool Orsos { get; set; }
public bool C3M { get; set; }
public bool Soft { get; set; }
public bool DIC { get; set; }
public bool Metalink { get; set; }
public bool Open_Med { get; set; }
public bool Muse { get; set; }
public bool MedQuest { get; set; }
public string Degree1 { get; set; }
public string Degree2 { get; set; }
public string Degree3 { get; set; }
}
}