First Time posting here, I won't use it as an excuse not to be helpful but this is driving me nuts. I am a complete noob, this isn't hw but this is my first (at home/for fun) type of project with asp.net mvc.
So here we go..
My Main menu looks as such.
@{
ViewBag.Title = "Index";
}
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#firstTab">View All
Vendors</a></li>
<li><a data-toggle="tab" href="#secondTab">Add New</a></li>
<li><a data-toggle="tab" href="#thirdTab">Remove</a></li>
</ul>
<div class="tab-content">
<div id="firstTab" class="tab-pane fade in active">@Html.Action("ViewAll")</div>
<div id="secondTab" class="tab-pane fade in">@Html.Action("AddOrEdit")</div>
<div id="thirdTab" class="tab-pane fade in">tab 3 content</div>
</div>
@section scripts
{
@Scripts.Render("~/bundles/jqueryval")
}
If I run my AddOrEdit.cshtml directly I can 'POST' just fine.
@model VendorApp.Models.VENDOR
@{
ViewBag.Title = "AddOrEdit";
}
@using (Html.BeginForm("AddOrEdit","Vendor",FormMethod.Post, new { enctype = "multipart/form-data", onSubmit = "return jQueryAjaxPost(this);" }))
{
@Html.AntiForgeryToken()
<div class="row">
<div class="form-horizontal">
<h4>Add Vendor</h4>
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.VENDOR_NUM)
<div class="col-md-6">
<div class="form-group">
@Html.LabelFor(model => model.VENDOR_NAME, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.VENDOR_NAME, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.VENDOR_NAME, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.STREET, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.STREET, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.STREET, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CITY, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CITY, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CITY, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.STATE, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.STATE, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.STATE, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Update" class="btn btn-default" />
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
@Html.LabelFor(model => model.ZIP, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.ZIP, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.ZIP, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.PHONE, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PHONE, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.PHONE, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.EMAIL, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.EMAIL, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EMAIL, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.SERVICE, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.SERVICE, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.SERVICE, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.NOTE, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.NOTE, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.NOTE, "", new { @class = "text-danger" })
</div>
</div>
</div>
</div>
</div>
}
And here is my Controller
using System;
using System.Collections.Generic;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VendorApp.Models;
namespace VendorApp.Controllers
{
public class VendorController : Controller
{
// GET: Vendor
public ActionResult Index()
{
return View();
}
//get all Vendors
public ActionResult ViewAll()
{
return View(GetAllVendor());
}
//numerate the vendors
IEnumerable<VENDOR>GetAllVendor()
{
using (Pref_VendorEntities db = new Pref_VendorEntities())
{
return db.VENDORs.ToList<VENDOR>();
}
}
/// <summary>
/// HTTP GET by DEFAULT
/// </summary>
/// <returns></returns>
public ActionResult AddOrEdit()
{
VENDOR vendor = new VENDOR();
return View(vendor);
}
/// <summary>
/// HTTP Post
/// </summary>
/// <returns></returns>
[HttpPost]
public ActionResult AddOrEdit(VENDOR vend)
{
using (Pref_VendorEntities db = new Pref_VendorEntities())
{
db.VENDORs.Add(vend);
db.SaveChanges();
}
return RedirectToAction("ViewAll");
}
}
}
If I Debug or Load directly from my index.cshtml I get This
But then if I go to click on my 'Add New' tab it looks like this.. Add New which is fine, but then it doesn't actually 'POST' the data.
If I directly load from this page the page displays as such
But it will actually let me 'POST' the data.. I hope I included enough information, but not too much to be overkill. I've tried looking around on here, and I don't know exactly what I'm doing wrong. Any help would be extremely appreciated and I'll be more than happy to elaborate on whatever else is required.
Thank you kindly!