Error - model sent to the view is incorrect - angularjs

I am getting following error message.Could somebody tell me why I am getting the following error message. My model is getting initialized with values when I debug the controller.
The model item passed into the dictionary is of type 'AngularJSMvcExample.Models.RegistrationVm', but this dictionary requires a model item of type 'System.String'.
My model code
namespace AngularJSMvcExample.Models
{
public class RegistrationVm
{
public string Courses { get; set; }
public string Instructors { get; set; }
}
}
My Controller code
namespace AngularJSMvcExample.Controllers
{
public class RegistrationController : Controller
{
private RegistrationVmBuilder _registrationVmBuilder = new RegistrationVmBuilder();
// GET: Registration
public ActionResult Index()
{
return View(_registrationVmBuilder.BuildRegistrationVm());
}
}
}
My ViewCode
#model AngularJSMvcExample.Models.RegistrationVm
#{
ViewBag.Title = "Registration";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="container" ng-controller="RegistrationController">
<div class="row">
<div class="navbar navbar-default">
<div class="navbar-header">
<ul class="nav navbar-nav">
<li>
<span class="navbar-brand">Registration</span>
</li>
</ul>
</div>
<div class="navbar-collapse collapse">
<ul class="nav nav-bar">
<li >Browse Catalog</li>
<li>Browse Instructors</li>
</ul>
</div>
</div>
</div>
</div>
My RegistrationVmBuilder code
namespace AngularJSMvcExample.Models
{
public class RegistrationVmBuilder
{
public RegistrationVm BuildRegistrationVm()
{
var registrationVm = new RegistrationVm
{
Courses = GetSerialisedCourse(),
Instructors = GetSerialisedInstructors()
};
return registrationVm;
}
public string GetSerialisedCourse()
{
var courses = new[]
{
new CourseVm {Number= "100", Name= "Physis", Instructor = "Jan"},
new CourseVm {Number= "101", Name= "Chemistry", Instructor = "Sal"},
new CourseVm {Number= "102", Name= "Biology", Instructor = "San"},
new CourseVm {Number= "103", Name= "History", Instructor = "Jack"},
new CourseVm {Number= "104", Name= "Maths", Instructor = "Rahul"}
};
var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
var serializeCourses = JsonConvert.SerializeObject(courses, settings);
return serializeCourses;
}
public string GetSerialisedInstructors()
{
var instructors = new[]
{
new InstructorsVm {Name= "Jan", Email= "jan.test#test.com", Roomno = "10"},
new InstructorsVm {Name= "Pal", Email= "pal.test#test.com", Roomno = "9"},
new InstructorsVm {Name= "San", Email= "san#test.com", Roomno = "11"},
new InstructorsVm {Name= "Jack", Email= "jack#test#test.com", Roomno = "12"},
new InstructorsVm {Name= "Rahul", Email= "rahul#test#test.com", Roomno = "15"}
};
var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() };
var serializeInstructors = JsonConvert.SerializeObject(instructors, settings);
return serializeInstructors;
}
}
}

Are you sure this is the index view?
#model AngularJSMvcExample.Models.RegistrationVm
#{
ViewBag.Title = "Registration";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="container" ng-controller="RegistrationController">
<div class="row">
<div class="navbar navbar-default">
<div class="navbar-header">
<ul class="nav navbar-nav">
<li>
<span class="navbar-brand">Registration</span>
</li>
</ul>
</div>
<div class="navbar-collapse collapse">
<ul class="nav nav-bar">
<li >Browse Catalog</li>
<li>Browse Instructors</li>
</ul>
</div>
</div>
</div>

Related

passing array from angular js to Web API = null

Dears, I am sending an object from angularjs to web API. all properties are sent to API and received correctly except 2 arrays, they are received by null in c# with out knowing a reason so if you could help it will be great
in the department (dep)array i am sending 1 value $scope.dep
in the cont array i am sending multipule values , may be pushing to the array is not correctly, i dont know
HTML
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="form-group">
<div class="col-xs-12">
<label class="control-label" for="name">Contracts <span class="danger">*</span></label>
</div>
<div class="col-xs-12">
<select id="example-post" class="form-control input-sm" multiple="multiple" ng-model="cont" ng-change="addcontracts(cont)">
<option ng-repeat="c in selectedcontracts" value="{{c.Sys_Key}}">{{c.Cont}}</option>
</select>
</div>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="form-group">
<div class="col-xs-12">
<label class="control-label" for="name">Department <span class="danger">*</span></label>
</div>
<div class="col-xs-12">
<select class="form-control input-sm" ng-model="dep" ng-options="d.Dep_key as d.dep for d in staffdepartments | unique:'dep'"></select>
</div>
</div>
</div>
Angular js
this.Repttx_PayRollTotal_Net = function (url, Attendlog) {
return $http.post(urlBase + '/' + url, Attendlog)
};
$scope.newcontracts = [];
$scope.addcontracts = function (cont) {
console.log(cont);
$scope.newcontracts = [];
$scope.newcontracts.push(cont) ;
console.log($scope.newcontracts);
}
var Attendlog = { DFrom: $scope.from1, Fg: $scope.fg, StaffKey: $scope.staffkey, StatusServ: $scope.jbsts, Cont: JSON.stringify($scope.newcontracts), Order: $scope.sor }
AtendanceReprtingSrv.Repttx_PayRollTotal_Net("AttendanceReprting/Repttx_PayRollTotal_Net", Attendlog).then(function (response) {
$scope.ttx = (response.data);
document.getElementById("frmrepodbc").src = $scope.ttx;
$("#dialog_PrintRptObc").modal("show");
})
C# class and its properties
public class Attendlogs
{
public DateTime DFrom { get; set; }
public short Fg { get; set; }
public long StaffKey { get; set; }
public int StatusServ { get; set; }
public int[] Dep { get; set; }
public int[] Cont { get; set; }
public int Order { get; set; }
}
C#
[HttpPost]
public string Repttx_PayRollTotal_Net([FromBody] Attendlogs logs)
{
DataTable DTres = new DataTable();
DTres = null;
HR_ReportingTimeAttendDL.ReportiingDL hr = new HR_ReportingTimeAttendDL.ReportiingDL();
DTres = hr.AttendLog(logs.DFrom, logs.Fg, logs.StaffKey, logs.StatusServ, logs.Dep, logs.Cont, logs.Order);
Thanks in advance
you are sending the arrays as objects to your api
Cont: JSON.stringify($scope.newcontracts)
you might need to loop on your data and push ids into arrays , and send this array to Backend
because at the model on Attendlogs class on the Backend side , you are expecting an integer array.

Set img src property from byte[]

I'm trying to show the thumbnailPhoto property of an ActiveDirectory user on an MVC View.
I'm parsing the needed properties to a List of a class named Employee:
for (int counter = 0; counter < resultCol.Count; counter++)
{
result = resultCol[counter];
if (result.Properties.Contains("samaccountname") &&
result.Properties.Contains("displayname") &&
result.Properties.Contains("sn") &&
result.Properties.Contains("givenName"))
{
list.Add(new Employee
{
Email = (String)result.Properties["samaccountname"][0],
FirstName = (String)result.Properties["givenName"][0],
LastName = (String)result.Properties["sn"][0],
pictureBLOB = result.Properties.Contains("thumbnailPhoto") ? (byte[])result.Properties["thumbnailPhoto"][0] : null,
});
}
}
I did some research on how to display the picture on the Index View and found this as a possible solution:
<div class="container">
#foreach (var item in Model)
{
String imgSrc = String.Empty;
String base64 = String.Empty;
if (item.pictureBLOB != null)
{
base64 = Convert.ToBase64String(item.pictureBLOB);
imgSrc = String.Format("data:image;base64,{0}", base64);
}
<div id="#Html.DisplayFor(i => item.Number)" class="col col-lg-2 col-md-4 col-sm-6">
<a class="post" mailto="#item.Email" href="#">
<img src="{#imgSrc}" title="#Html.DisplayFor(i => item.LastName), #Html.DisplayFor(i => item.FirstName)" />
#*onerror="this.src = '../../Content/Images/nopicture.gif';" />*#
</a>
</div>
}
</div>
But when I call the index page, the pictures won't be shown. Is there any other possibility to show the profile pictures?
Finally I found the solution. I simply had to remove the braces around #imgSrc in
<img src="{#imgSrc}" title="#Html.DisplayFor(i => item.LastName), #Html.DisplayFor(i => item.FirstName)" />

ng-model into ng-repeat Angularjs

I'm asking if is possible to do something as that in angular
<div ng-app="app">
<div ng-controller="mainController">
<ul ng-repeat="movie in movies |searchFilter:Filter.genre | searchFilter:Filter.name |searchFilter:Filter.pic ">
<li>{{movie.name}}</li>
</ul>
<h2>genre</h2>
<div>
<label>Comedy </label><input type="checkbox" ng-model="Filter.genre.Comedy" ng-true-value="Comedy" data-ng-false-value=''/><br/>
</div>
<h2>PIC</h2>
<label>aa</label><input type="checkbox" ng-model="Filter.pic.aa" ng-true-value="ciao" data-ng-false-value=''/><br/>
<h2>Name</h2>
<label>Shrek</label><input type="checkbox" ng-model="Filter.name.Shrek" ng-true-value="The God" data-ng-false-value=''/><br/>
</div>
</div>
i'm creating a checkbox for filter on different fields (size,name,genre)
ill have a list of avaible sizes,names and genres .
The issue is on ng-model and i tried to write it as "Filter.genre.genre.name" or
"Filter["genre"+genre.name]" and also "Filter.genre[genre.name]" but still not work .
the js.file is
var app =angular.module('app', []);
app.controller('mainController', function($scope) {
$scope.movies = [{name:'Shrek', genre:'Comedy',pic:"cc"},
{name:'Die Hard', genre:'Comedy',pic:"aa"},
{name:'The Godfather', genre:'Drama',pic:"ciao"},
{name:'The Godher', genre:'Comedy',pic:"lel"}];
$scope.genres = [{name:"Comedy"},{name:"Action"},{name:"Drama"}];
});
app.filter('searchFilter',function($filter) {
return function(items,searchfilter) {
var isSearchFilterEmpty = true;
//searchfilter darf nicht leer sein
angular.forEach(searchfilter, function(searchstring) {
if(searchstring !=null && searchstring !=""){
isSearchFilterEmpty= false;
}
});
if(!isSearchFilterEmpty){
var result = [];
angular.forEach(items, function(item) {
var isFound = false;
angular.forEach(item, function(term,key) {
if(term != null && !isFound){
term = term.toLowerCase();
angular.forEach(searchfilter, function(searchstring) {
searchstring = searchstring.toLowerCase();
if(searchstring !="" && term.indexOf(searchstring) !=-1 && !isFound){
result.push(item);
isFound = true;
// console.log(key,term);
}
});
}
});
});
return result;
}else{
return items;
}
}
});
if i make 3 different labels for the field Comedy, Action and Drama with ng-models called as
ng-model="Filter.genre.Comedy" ; ng-model="Filter.genre.Action" and ng-model="Filter.genre.Drama"
it work but it doesnt work if i try to write it into ng-repeat . I hope to have been clearer
In this sample i try to handle your question by change the Model of your page.
we have:
list of movies array => $scope.movies = []
dynamic filters array => $scope.genres = [], $scope.years = [] or more
our target:
Create a dynamic filters to search in movies
what we do
$scope.filterHandler = function (key, value) {}
Run when user start searching on input or select, this function help us to create a filter as object by sending key and value which result is {key:value}
$scope.searchTypeHandler = function (type, dependTo) {}
Run when our filters has some array for example genre has genres as dropdown select, this function help us to return the array which depend to the filter.
var app = angular.module("app", []);
app.controller("ctrl", [
"$scope",
function($scope) {
//your options
$scope.movies = [{
name: 'Shrek',
genre: 'Comedy',
year: 2000
},
{
name: 'Die Hard',
genre: 'Action',
year: 2000
},
{
name: 'The Godfather',
genre: 'Drama',
year: 2015
},
{
name: 'The Godher',
genre: 'Comedy',
year: 2017
}
];
$scope.genres = [{
name: "Comedy"
},
{
name: "Action"
},
{
name: "Drama"
}
];
$scope.years = [{
name: 2000
},
{
name: 2015
},
{
name: 2017
}
];
//
$scope.filter = {}
$scope.filterHandler = function(key, value) {
var object = {};
object[key] = value;
$scope.filter["find"] = object;
};
$scope.searchTypeHandler = function(type, dependTo) {
$scope.filter = {};
$scope.filter.searchType = type;
$scope.filter.options = undefined;
if (dependTo != null) {
$scope.filter.options = $scope[dependTo];
}
};
//default
$scope.searchTypeHandler("name");
}
]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<div class="container" ng-app="app" ng-controller="ctrl">
<div class="page-header">
<div class="row">
<div class="col-lg-12">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
<h4>Movies</h4>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6 pull-right">
<div class="input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
By {{filter.searchType}}
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-left">
<li><a ng-click="searchTypeHandler('genre', 'genres')">Filter By Genre</a></li>
<li><a ng-click="searchTypeHandler('name', null)">Filter By Name</a></li>
<li><a ng-click="searchTypeHandler('year', 'years')">Filter By Year</a></li>
</ul>
</div>
<input ng-hide="filter.options" type="text" class="form-control" ng-model="filter.query" ng-change="filterHandler(filter.searchType, filter.query)">
<select ng-show="filter.options" class="form-control" ng-model="filter.option" ng-change="filterHandler(filter.searchType, filter.option)" ng-options="option.name as option.name for option in filter.options"></select>
</div>
<!-- /input-group -->
</div>
</div>
</div>
</div>
<ul class="list-group">
<li class="list-group-item" ng-repeat="movie in movies | filter: filter.find">
{{movie.name}} - <label class="label label-info">Ggenre: {{movie.genre}}</label> - <label class="label label-default">Year: {{movie.year}}</label>
</li>
</ul>
</div>

Persisting Data To SQL Server via ASP.NET MVC

I am trying to persist the information in the 'auction' variable, to the table 'Auction', which has not been created yet. Entity framework is supposed to create it for me I understand. As you see, my program has made it to the point where the form data is contained in the 'auction' variable. But as you can see the debugger is stopped on 'db.Auction.Add(auction)'.
Why won't the program proceed by letting the db add the data in the 'auction' variable, to the Auction table?
I'd appreciate it.
Thanks,
CM
Thank you for replying so far but the suggestions are not working. I've written in my code as well as shown the error message again which is the same message I had that started this thread.
The View
#model MvcAuction.Models.Auction
#{
ViewBag.Title = "CreateAuctionItem";
}
<h2>#ViewBag.Title.</h2>
<div id="createAuctionItemSection">
#using (Html.BeginForm("Create", "Auctions", FormMethod.Post,
new { #class = "form-horizontal", #id =
"registerForm", role = "form" }))
{
#Html.AntiForgeryToken()
<h4>Create An Item For Auction.</h4>
<hr />
#Html.ValidationSummary("", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(m => m.Title, new { #class = "col-md-2 control-
label" })
<div class="col-md-10">
#Html.TextBoxFor(m => m.Title, new { #class = "form-control", #id = "title" })
</div>
</div>
#Html.ValidationSummary("", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(m => m.StartDate, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(model => model.StartDate, "{0:yyyy-MM-dd}", new { type = "date" })
</div>
</div>
#Html.ValidationSummary("", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(m => m.EndDate, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(model => model.EndDate, "{0:yyyy-MM-dd}", new { type = "date" })
</div>
</div>
#Html.ValidationSummary("", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(m => m.DeliveryCost, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(m => m.DeliveryCost, new { #class = "form-control", #id = "deliveryCost" })
</div>
</div>
#Html.ValidationSummary("", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(m => m.StartBid, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(m => m.StartBid, new { #class = "form-control", #id = "startBid" })
</div>
</div>
#Html.ValidationSummary("", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(m => m.BuyNowPrice, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(m => m.BuyNowPrice, new { #class = "form-control", #id = "buyNowPrice" })
</div>
</div>
#Html.ValidationSummary("", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(m => m.BuyNowEnabled, new { #Value = "Show Buy Now Price?", #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.CheckBoxFor(m => m.BuyNowEnabled, new { #class = "form-control", #id = "buyNowEnabled" })
</div>
</div>
#Html.ValidationSummary("", new { #class = "text-danger" })
<div class="form-group">
#Html.LabelFor(m => m.Description, new { #class = "col-md-2 control-label" })
<div class="col-md-10">
#Html.TextBoxFor(m => m.Description, new { #class = "form-control", #id = "description" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Create Item" />
</div>
</div>
}
<img src="~/Content/Images/progress.gif" id="progress" style="display:none;" />
<h3>#ViewBag.TheMessage</h3>
</div><!--End createAuctionItemSection-->
The Model
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace MvcAuction.Models
{
public class Auction
{
public long Id { get; set; }
[Required]
[Column(TypeName = "varchar")]
[Display(Name = "Title")]
public String Title { get; set; }
public string ImageURL { get; set; }
[Required]
[Column(TypeName = "date")]
[Display(Name = "Start Date")]
public DateTime StartDate { get; set; }
[Required]
[Column(TypeName = "date")]
[Display(Name = "End Date")]
public DateTime EndDate { get; set; }
[Required]
[Column(TypeName = "decimal")]
[Display(Name = "Delivery Cost")]
public decimal DeliveryCost { get; set; }
[Required]
[Column(TypeName = "decimal")]
[Display(Name = "Start Bid")]
public decimal StartBid { get; set; }
[Column(TypeName = "decimal")]
[Display(Name = "Buy Now Price")]
public decimal BuyNowPrice { get; set; }
[Column(TypeName = "bool")]
[Display(Name = "Buy Now Enabled")]
public Boolean BuyNowEnabled { get; set; }
[Column(TypeName = "varchar")]
[Display(Name = "Description")]
public String Description { get; set; }
[Column(TypeName = "int")]
[Display(Name = "View Count")]
public int ViewCount = 0;
public decimal? getCurrentTopBid()
{
return StartBid;
}
}
}
The Controller Action
[HttpPost]
public ActionResult Create(Auction auction )
{
if (ModelState.IsValid)
{
var db = new AuctionsDataContext();
db.Auction.Add(auction);
db.SaveChanges();
return RedirectToAction("Index");
}
return View();
}
Action is already apart of the DbContext class as a DbSet. Also the view already sends the Model information back you don't need that as an overloaded parameter. Change your create post to
public class AuctionsController : Controller
{
private readonly AuctionsDataContext_context;
public AuctionsController(AuctionsDataContext context)
{
_context = context;
}
public ActionResult Create ( Bind[("Id,Title,StartDate,EndDate,DeliveryCost,StartBid,BuyNowPrice,BuyNowEnabled,Description")] Auction auction)
{
if (ModelState.IsValid)
{
_context.Add(auction);
await _context.SaveChangesAsync();
return RedirectToAction("Index");
}
return View();
}

How to display the last inserted ID (primary key) of a table in a html textbox that is in a relationship with a foreign key of another table in mvc

I'm new to asp.net and MVC, and I have a problem.
I know that this is something simple but I do not know how to do it. I seek advice and would like to thank you in advance for any help.
This is my problem:
I have 2 tables: table X: ID (primary key), Number; and table Y: ID (primary key), NID (foreign key with relationship with table X), etc.
What I want to know is how to display last inserted ID into the view of table Y on an Html editor for NID the last value of ID (table X)?
For example, I create a new row in table X, and when I want to create the row in table Y that corresponds with table X to automatically get the last ID inserted in the textbox or editor?
Can anybody give me some kind of reference or an example! Thank you for your help! Sorry for any bad spelling.
Here we go . I tested this and it returned me the model properties along with files posted . This example gives you ideea how POSt method used in MVC and how to send model propertied back to controller .
//-- this is the controller
public class FileUploadDemoController : Controller
{
//
// GET: /FileUploadDemo/
public ActionResult Index()
{
// here find the last if of the FileUploadtable
var ctx = new TestDbContext();
var maxId = ctx.Fileuploads.ToList().OrderByDescending(u => u.Id).FirstOrDefault();
var newId = maxId == null ? 1 : maxId.Id + 1;
return View("Index", new FileUploadModel { Id= newId });
}
[HttpPost]
public ActionResult PostForm(FileUploadModel model)
{
// here you have NewId in model.Id method ; Now ypour table b in my case is fileeuploadhistory I want to insert a new record with this model.Id
using (var ctx = new TestDbContext())
{
var curretFile = ctx.Fileuploads.FirstOrDefault(x => x.Id == model.Id);
if (curretFile==null)
{
curretFile=new FileUploadModel { Name=model.Name , ValidFromDate= model.ValidFromDate};
}
curretFile.History = new FileUploadHistory { InsertedDate = DateTime.Now };
ctx.Fileuploads.Add(curretFile);
ctx.SaveChanges();
}
return View("Index", model);
}
}
-- These are MY EntityFramework entities and I am using same on Views as well
public class FileUploadModel
{
public FileUploadModel()
{
}
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Name { get; set; }
public string ValidFromDate { get; set; }
public int HistoryId { get; set; }
[ForeignKeyAttribute("HistoryId")]
public virtual FileUploadHistory History { get; set; }
}
public class FileUploadHistory
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public DateTime InsertedDate { get; set; }
}
-- Finaly the cshml file . The import point is to use new { enctype = "multipart/form-data" } inside BeginForm . // the page from where you will post the data . Please change you model class in place of FileUploadModel I created for me .
#model WebApplication1.Models.FileUploadModel
#using (Html.BeginForm("PostForm", "FileUploadDemo", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="panel">
<div class="panel-body">
<div class="form-group row">
<div class="col-md-2 form-label">
<label>ID:</label>
</div>
<div class="col-md-6">
#Html.TextAreaFor(x => x.Id , new { #class = "form-control" })
</div>
</div>
<div class="form-group row">
<div class="col-md-2 form-label">
<label>Name:</label>
</div>
<div class="col-md-6">
#Html.TextAreaFor(x => x.Name, new { #class = "form-control" })
</div>
</div>
<div class="form-group row">
<div class="col-md-2 form-label">
<label>Date</label>
</div>
<div class="col-md-6">
#Html.TextAreaFor(x => x.ValidFromDate, new { #class = "form-control" })
</div>
</div>
<div class="col-md-10">
<div class="form-group row">
<div class="col-md-2 form-label">
<label>Select File<i class="required-field">*</i>:</label>
</div>
<div class="col-md-8">
<input type="file" class="file-upload" style="margin: 0px;" hidden="hidden" accept=".xlsx" name="file" id="file" />
</div>
</div>
</div>
<div class="form-group row">
<div class="col-md-3 pull-right text-right">
<button class="btn btn-primary" id="process-submission" type="submit">
Submit
</button>
</div>
</div>
</div>
</div>
}

Resources