Html.ActionLink doesn't call at all - asp.net-mvc

I am having some problems solving this. The thing is, this is the only place it doesn't work, everywhere else in my project it works just fine and it's all the same.
here is my link:
<td class="col-sm-1 col-lg-1">#Html.ActionLink("Edit", "EditGrowWeek", "FinishedProductionMaintanance", new { #id = Model.growWeek.GWID }, new { #data_toggle = "modal", #data_target = "#editGrowWeek" })</td>
my controller:
[HttpGet]
public ActionResult EditGrowWeek(int id)
{
viewModel.growWeek = _ProductionGrowWeekRepository.GetOne(id);
return PartialView(viewModel);
}
[HttpPost]
//[ValidateAntiForgeryToken]
public ActionResult EditGrowWeek([Bind(Prefix="growWeek")] ProductionGrowWeek growWeek)
{
var growWeeks = _ProductionGrowWeekRepository.GetAll(growWeek.GProfileNo);
foreach (var week in growWeeks)
{
if (ModelState.IsValid)
{
_ProductionGrowWeekRepository.Edit(week);
}
}
return RedirectToAction("IndexGrowProfiles");
}
and finally my view:
#model SISCOM.ViewModel.FinishedProductionMaintananceViewModel
#{
Layout = null;
}
<div class="modal fade in" id="editGrowWeek" tabindex="-1" role="dialog" aria-labelledby="MyModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dissmiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<div class="modal-body">
#using (Html.BeginForm("EditGrowWeek", "FinishedProductionMaintanance", FormMethod.Post))
{
#*#Html.AntiForgeryToken()*#
<form id="form">
#Html.ValidationSummary(true)
#Html.HiddenFor(model => model.growWeek.GWID)
#Html.HiddenFor(model => model.growWeek.CutSupplierCode)
#Html.HiddenFor(model => model.growWeek.DelvyWk)
#Html.HiddenFor(model => model.growWeek.Description_ID_)
#Html.HiddenFor(model => model.growWeek.Description_Product_)
#Html.HiddenFor(model => model.growWeek.Despatch)
#Html.HiddenFor(model => model.growWeek.FinishedDuration)
#Html.HiddenFor(model => model.growWeek.FinishedSite)
#Html.HiddenFor(model => model.growWeek.GapUpHandSite)
#Html.HiddenFor(model => model.growWeek.GapUpMCSite)
#Html.HiddenFor(model => model.growWeek.GerminationDuration)
#Html.HiddenFor(model => model.growWeek.GerminationSite)
#Html.HiddenFor(model => model.growWeek.Germinator)
#Html.HiddenFor(model => model.growWeek.GerminatorDuration)
#Html.HiddenFor(model => model.growWeek.GerminatorSite)
#Html.HiddenFor(model => model.growWeek.GProfileNo)
#Html.HiddenFor(model => model.growWeek.GrowWks1)
#Html.HiddenFor(model => model.growWeek.GrowWks2)
#Html.HiddenFor(model => model.growWeek.GrowWks3)
#Html.HiddenFor(model => model.growWeek.GrowWks4)
#Html.HiddenFor(model => model.growWeek.GrowWks5)
#Html.HiddenFor(model => model.growWeek.OrderWK)
#Html.HiddenFor(model => model.growWeek.PreGapDuration)
#Html.HiddenFor(model => model.growWeek.PreGapSite)
#Html.HiddenFor(model => model.growWeek.PrickOut)
#Html.HiddenFor(model => model.growWeek.PrickOutSite)
#Html.HiddenFor(model => model.growWeek.Priority)
#Html.HiddenFor(model => model.growWeek.ProdGrp)
#Html.HiddenFor(model => model.growWeek.ProdSeries)
#Html.HiddenFor(model => model.growWeek.ProdSeriesDetail)
#Html.HiddenFor(model => model.growWeek.ProductionGrowProfile)
#Html.HiddenFor(model => model.growWeek.RangeUpdateFlag)
#Html.HiddenFor(model => model.growWeek.Rooting_GermAssess)
#Html.HiddenFor(model => model.growWeek.SiteGrown)
#Html.HiddenFor(model => model.growWeek.SiteRange)
#Html.HiddenFor(model => model.growWeek.SiteSown)
#Html.HiddenFor(model => model.growWeek.Topping)
#Html.HiddenFor(model => model.growWeek.ToppingCode)
#Html.HiddenFor(model => model.growWeek.Transplant)
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.WksToDesp, "Weeks to despatch")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.WksToDesp, null, new { #class = "form-control", #placeholder = "Weeks to despatch" })
#Html.ValidationMessageFor(p => p.growWeek.WksToDesp, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.GapUp, "Gap up")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.GapUp, null, new { #class = "form-control", #placeholder = "Gap up" })
#Html.ValidationMessageFor(p => p.growWeek.GapUp, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.Pinch1, "Pinch1")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.Pinch1, null, new { #class = "form-control", #placeholder = "Pinch1" })
#Html.ValidationMessageFor(p => p.growWeek.Pinch1, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.Pinch2, "Pinch2")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.Pinch2, null, new { #class = "form-control", #placeholder = "Pinch2" })
#Html.ValidationMessageFor(p => p.growWeek.Pinch2, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.Space1, "Space1")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.Space1, null, new { #class = "form-control", #placeholder = "Space1" })
#Html.ValidationMessageFor(p => p.growWeek.Space1, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.Space2, "Space2")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.Space2, null, new { #class = "form-control", #placeholder = "Space2" })
#Html.ValidationMessageFor(p => p.growWeek.Space2, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.Space3, "Space3")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.Space3, null, new { #class = "form-control", #placeholder = "Space3" })
#Html.ValidationMessageFor(p => p.growWeek.Space3, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="editor-label">
#Html.LabelFor(p => p.growWeek.Check1, "Check1")
</div>
<div class="editor-field">
#Html.TextBoxFor(p => p.growWeek.Check1, null, new { #class = "form-control", #placeholder = "Check1" })
#Html.ValidationMessageFor(p => p.growWeek.Check1, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Edit" class="btn btn-default" />
</div>
</div>
</form>
}
</div>
</div>
</div>
</div>
I've been checking everywhere and this one doesn't make a call at all... any ideeas?
P.S. ... this might be connected so, on this page, (On the index that renders this partial) my footer is being rendered somewhere in the middle of my page in code..

This doesn't make a lot of sense but here it is. The problem was that everytime i generated values for that table it removed the partial view following it for some reason (if anyone can make sense of this behaviour and can explain please do.)
so, my index for this page used to look like this:
<div class="tab-content col-md-9 col-lg-9 growProfilePage">
<div class="col-md-12 col-lg-12">
<div class="col-md-4">
#{ Html.RenderPartial("ListGrowProfiles");}
</div>
<div class="col-md-8">
#{ Html.RenderPartial("ListGrowWeeks");}
#{ Html.RenderPartial("EditGrowWeek");}
</div>
</div>
</div>
now it looks like this:
<div class="tab-content col-md-9 col-lg-9 growProfilePage">
<div class="col-md-12 col-lg-12">
#{ Html.RenderPartial("EditGrowWeek");}
<div class="col-md-4">
#{ Html.RenderPartial("ListGrowProfiles");}
</div>
<div class="col-md-8">
#{ Html.RenderPartial("ListGrowWeeks");}
</div>
</div>
</div>
and it all works (curiously enough, on other pages it's still like before, the edit following the list and it works like that).

Related

Passing Model to the partial view doesn't work

The file "Add.cshtml" is calling the partial view "_ManagePartial.cshtml" and passing the "Model""however the "Model " is not being picked up in the partial view.
When I include the code that's on the partial view into "Add.cshtml" everything works great.
Please advise what I''m doing wrong.
Error Message:
Click here to see the error message screenshot
File: _ManagePartial.cshtml
<div class="row">
<div class="col-md-4">
<div class="form-group">
#Html.LabelFor(model => model.UserName)
#Html.EditorFor(model => model.UserName, new { htmlAttributes = new { #class = "form-control input-lg" } })
#Html.ValidationMessageFor(model => model.UserName, "", new { #class = "text-danger" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.UserPassword)
#Html.EditorFor(model => model.UserPassword, new { htmlAttributes = new { #class = "form-control input-lg" } })
#Html.ValidationMessageFor(model => model.UserPassword, "", new { #class = "text-danger" })
</div>
<div class="form-group"><button type="submit" class="btn btn-primary btn-lg">Submit</button></div>
</div>
<div class="col-md-4">
<div class="form-group">
#Html.LabelFor(model => model.UserEmail)
#Html.EditorFor(model => model.UserEmail, new { htmlAttributes = new { #class = "form-control input-lg" } })
#Html.ValidationMessageFor(model => model.UserEmail, "", new { #class = "text-danger" })
</div>
<div class="form-group">
#Html.LabelFor(model => model.UserConfirmPassword)
<input type="password" class="form-control input-lg" name="UserConfirmPassword">
</div>
</div>
</div>
File: Add.cshtml
#model CardDistro.Models.AddUserViewModel
#{
ViewBag.Current = "Users#Index";
String Action = ViewBag.FormAction;
}
<h2 class="page-header">#ViewBag.Title</h2>
#using (Html.BeginForm(Action, "Users", FormMethod.Post, new { id = "SiteAddUserContainer" }))
{
<input type="hidden" name="UserID" value="#Model.UserID" />
if (ViewBag.Retval != null){
<div class="row"><div class="col-md-8"><div class="alert alert-danger">#ViewBag.Retval</div></div></div>
}
Html.RenderPartial("_ManagePartial", Model);
}
_ManagePartial.cshtml needs to identify the model by starting the partial view with
#model CardDistro.Models.AddUserViewModel
so the compiler knows what to do with model=>UserName

how to show validation summary with asterisk in mvc?

In this Form used validation summary for errors.
View:-
<div class="col-md-12 table-bordered" style="padding: 20px; margin:10px;">
<div class="col-md-12">#Html.ValidationSummary(false,"Please Correct Following details :", new { #class = "text-danger" })</div>
<div class="col-md-12" style="padding:10px;">
<div class="col-md-6">
<div style="width:95%;">
#Html.LabelFor(Model => Model.ItemName, new { style = "font-weight:bold;", #maxlength = "100" })
#Html.TextBoxFor(Model => Model.ItemName)
<span class="text-danger"> #Html.ValidationMessageFor(Model => Model.ItemName) </span>
</div>
</div>
<div class="col-md-6">
<div style="width:75%;">
#Html.LabelFor(Model => Model.ActiveProductGroup, new { style = "font-weight:bold;" })
#Html.DropDownListFor(Model => Model.ProductGroupID, new SelectList(ViewBag.ActiveProductGroup, "Value", "Text"), "--Select Value--", new { style = "Width:95%" })
<span class="text-danger"> #Html.ValidationMessageFor(Model => Model.ActiveProductGroup) </span>
</div>
</div>
</div>
<div class="col-md-12" style="padding:10px;">
<div class="col-md-3">
<div style="width:70%;">
#Html.LabelFor(Model => Model.SequenceNumber, new { style = "font-weight:bold;" })
#Html.TextBoxFor(Model => Model.SequenceNumber, new { style = "text-align:right", #maxlength = "3" })
<span class="text-danger"> #Html.ValidationMessageFor(Model => Model.SequenceNumber) </span>
</div>
</div>
<div class="col-md-3">
<div style="width:50%;">
#Html.LabelFor(Model => Model.UnitPrice, new { style = "font-weight:bold;" })
#Html.TextBoxFor(Model => Model.UnitPrice, new { style = "text-align:right", #maxlength = "5" })
<span class="text-danger"> #Html.ValidationMessageFor(Model => Model.UnitPrice) </span>
</div>
</div>
<div class="col-md-3">
<div style="width:50%;">
#Html.LabelFor(Model => Model.Quantity, new { style = "font-weight:bold;" })
#Html.TextBoxFor(Model => Model.Quantity, new { style = "text-align:right", #maxlength = "5" })
<span class="text-danger"> #Html.ValidationMessageFor(Model => Model.Quantity) </span>
</div>
</div>
<div class="col-md-3">
<div style="width:80%;">
#Html.LabelFor(Model => Model.EstimatedDeliveryDays, new { style = "font-weight:bold;" })
#Html.TextBoxFor(Model => Model.EstimatedDeliveryDays, new { style = "text-align:right", #maxlength = "2" })
<span class="text-danger"> #Html.ValidationMessageFor(Model => Model.EstimatedDeliveryDays) </span>
</div>
</div>
</div>
</div>
In this used html.validation summary
In this Form it should show asterisk (*) sign below textbox and error in validation summary
how to achieve it?
Can't you use the Required attribute in your model?
Example:
public class ClassName{
[Required(ErrorMessage = "* Please enter Item Name")]
public string ItemName {get;set;}
}

MVC Post Action method not firing

I am currently working on inserting records functionality of MVC 5 application. For some reason the post action method doesn't fire. I am created an button on View that should trigger the post action method. Not sure why it is not firing. The form elements are in partial view and the button control is not the main view that host the partial view.
Here is the code
Main view
#model CC.GRP.MCRequest.ViewModels.NewRequestViewModel
<div class="newrequest">
#Html.Partial("~/Views/Request/RequestHeaderView.cshtml");
</div>
<div id="buttonalign" class="buttonalign" >
<button type="button" class="btn btn-primary">Submit</button>
<button type="button" class="btn btn-default" onclick="location.href='#Url.Action("Request_Insert", "Request")'" >Save as draft</button>
</div>
Request Header View
#model CC.GRP.MCRequest.ViewModels.NewRequestViewModel
#using (Html.BeginForm())
{
<div id="NewRequest">
<div class="row">
<div class="col-md-4">
<div class="form-group">
#Html.LabelFor(model => model.RequestID, htmlAttributes: new { #class = "control-label col-md-4" })
<div class="col-md-6">
<div class="editor-field">
#Html.EditorFor(model => model.RequestID, new { htmlAttributes = new { #class = "form-control", style = "width:100%", #readonly = "readonly" } })
</div>
#Html.ValidationMessageFor(model => model.RequestID, "", new { #class = "text-danger" })
</div>
</div>
<div class="clearfix"></div>
<div class="form-group">
#Html.LabelFor(model => model.Name1, htmlAttributes: new { #class = "control-label col-md-4" })
<div class="col-md-6">
<div class="editor-field">
#(Html.Kendo().ComboBoxFor(model => model.Name1)
.HtmlAttributes(new { style = "width:100%" })
.DataTextField("Name1")
.DataValueField("CustomerMasterDataId")
.DataSource(dataSource => dataSource
.Read(read => read.Action("RequestHeader_CustomerData", "Request").Type(HttpVerbs.Post))
)
.Events(e =>
{
e.Change("onCustomerComboChange");
})
)
</div>
#Html.ValidationMessageFor(model => model.CustomerNumber, "", new { #class = "text-danger" })
</div>
</div>
<div class="clearfix"></div>
<div class="form-group">
#Html.LabelFor(model => model.CustomerNumber, htmlAttributes: new { #class = "control-label col-md-4" })
<div class="col-md-6">
<div class="editor-field">
#Html.EditorFor(model => model.CustomerNumber, new { htmlAttributes = new { #class = "form-control", style = "width:100%", #readonly = "readonly" } })
</div>
#Html.ValidationMessageFor(model => model.CustomerNumber, "", new { #class = "text-danger" })
</div>
</div>
</div>
</div>
Request Controller
[HttpPost]
public ActionResult Request_Insert(NewRequestViewModel userVM)
{
NewRequestViewModel newReqeustViewModel = new NewRequestViewModel();
if (!ModelState.IsValid)
{
return null;
}
requestRepository.CreateRequest(Mapper.Map<Request>(userVM));
//return Json(requestRepository.CreateRequest(userVM));
return View("NewRequestView", newReqeustViewModel);
}
you should put
<div id="buttonalign" class="buttonalign" >
<button type="button" class="btn btn-primary">Submit</button>
<button type="button" class="btn btn-default" onclick="location.href='#Url.Action("Request_Insert", "Request")'" >Save as draft</button>
</div>
inside
#using (Html.BeginForm("Request_Insert", "Request", FormMethod.Post))
{
}
in Request Header View
and
update
<button type="button" class="btn btn-primary">Submit</button>
to
<button type="submit" class="btn btn-primary">Submit</button>

Bootstrap form labels not placed before the textbox?

I'm not seeing why the following code is putting the labels to the right of the textbox instead of the to the left? Should I be using <div class="row"> around the <div class="form-group">?
Anyone know what I'm missing?
<div class="form-horizontal">
#using (Html.BeginForm("EditClockGroup", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
#Html.ValidationSummary(false, "", new { #class = "alert alert-danger" })
#Html.HiddenFor(model => model.GroupId, null)
<div class="form-group">
#Html.LabelFor(m => m.GroupId, new { #class = "col-md-2 control-label" })
#Html.TextBoxFor(m => m.GroupId, new { #class = "col-md-7 form-control" })
</div>
<div class="form-group">
#Html.LabelFor(m => m.GroupName, new { #class = "col-md-2 control-label" })
#Html.TextBoxFor(m => m.GroupName, new { #class = "col-md-7 form-control" })
</div>
<div class="form-group">
<div class="col-md-7 col-md-offset-2">
<input type="submit" value="Update" class="btn btn-primary" />
</div>
</div>
}
</div>
You cannot apply col-md-7 to input tag. Instead, you need to place input inside div.
<div class="form-group">
#Html.LabelFor(m => m.GroupId, new { #class = "col-md-2 control-label" })
<div class="col-md-7">
#Html.TextBoxFor(m => m.GroupId, new { #class = "form-control" })
</div>
</div>

How to set Session to ReceiveInvoice in Combobox to hold the Receive_ID for very next Entry

I want to use receive invoice for very next entry using session but it don't. Here I populate Receive InvoiceNo in create controller. please help me..
var rmaster = db.FactoryReceiveMaster.ToList();
List<SelectListItem> lstFactoryReceiveMaster = new List<SelectListItem>();
if (rmaster != null && rmaster.Count > 0)
{
foreach (var rInvoice in rmaster)
{
SelectListItem item = new SelectListItem { Text = rInvoice.RInvoiceNo, Value = rInvoice.Receive_ID.ToString(), Selected = false };
lstFactoryReceiveMaster.Add(item);
}
}
Session["lstFactoryReceiveMaster"] = lstFactoryReceiveMaster;
model.AssembleInvoice = lstFactoryReceiveMaster;
Create View....
#using Kendo.Mvc.UI;
#model MvcMahindraTwoWheelerERP.Models.FactoryProductAssembledViewModel
<div class="panel panel-info">
<div class="panel-heading">
<h3 style="font-family:cursive;font-size:large;"> Assemble Product - Entry Form</h3>
</div>
<div class="panel-body">
#using (Html.BeginForm("Create", "FactoryAssembleProduct", FormMethod.Post))
{
#Html.ValidationSummary(true, "", new { #class = "text-danger" })
<div class="form-horizontal">
<div class="form-group">
<div class="form-group">
<div class="col-sm-offset-1 col-sm-4">
#Html.LabelFor(model => model.Assembled_Date)
#(Html.Kendo().DatePickerFor(model => model.Assembled_Date).Format("dd/MMM/yyyy").HtmlAttributes(new { #style = "width:100%;"}))
#Html.ValidationMessageFor(model => model.Assembled_Date)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-4">
#Html.LabelFor(model => model.FactoryReceiveMaster.RInvoiceNo)
#(Html.Kendo().ComboBoxFor(model => model.FactoryReceiveMaster.Receive_ID).BindTo(Model.AssembleInvoice).HtmlAttributes(new {#style = "width:100%;"}))
#Html.ValidationMessageFor(model => model.FactoryReceiveMaster.Receive_ID)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-4">
#Html.LabelFor(model => model.Product.ProdCode)
#(Html.Kendo().ComboBoxFor(model => model.Product.ProductID).BindTo(Model.AssembleProducts).HtmlAttributes(new {id="ProductID", #style = "width:100%;"}).Filter(FilterType.Contains))
#Html.ValidationMessageFor(model => model.Product.ProductID)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-4">
#Html.LabelFor(model => model.Description)
#Html.TextBoxFor(model => model.Description, new { id="descriptipn", #class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-4">
#Html.LabelFor(model => model.Chassis_No)
#Html.TextBoxFor(model => model.Chassis_No, new {#class = "form-control" })
#Html.ValidationMessageFor(model => model.Chassis_No)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-4">
#Html.LabelFor(model => model.Engine_No)
#Html.TextBoxFor(model => model.Engine_No, new {#class = "form-control" })
#Html.ValidationMessageFor(model => model.Engine_No)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-4">
#Html.LabelFor(model => model.Key_No)
#Html.TextBoxFor(model => model.Key_No, new {#class = "form-control" })
#Html.ValidationMessageFor(model => model.Key_No)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-4">
#Html.LabelFor(model => model.Remarks)
#Html.TextBoxFor(model => model.Remarks, new {#class = "form-control" })
#Html.ValidationMessageFor(model =>model.Remarks)
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-4">
<input type="submit" class="btn btn-lg btn-primary btn-block" value="Save Changes" />
</div>
</div>
</div>
</div>
}
</div>
Now, now how to fix it ...?

Resources