Asp.net mvc ASP.NET MVC-重用局部视图?
我正在尝试在另一个页面中重用“Competencia”作为部分视图。就像旧的web控件一样。 当我以“普通页面”运行时,说Asp.net mvc ASP.NET MVC-重用局部视图?,asp.net-mvc,razor,asp.net-mvc-partialview,Asp.net Mvc,Razor,Asp.net Mvc Partialview,我正在尝试在另一个页面中重用“Competencia”作为部分视图。就像旧的web控件一样。 当我以“普通页面”运行时,说 http://mydomain/Competencia 控件工作正常。当我使用is作为局部视图时,它不会渲染 @section Scripts { <script src="@Url.Content("~/ViewScripts/Competencia/Index.js")" type="text/javascript"></scrip
http://mydomain/Competencia
控件工作正常。当我使用is作为局部视图时,它不会渲染
@section Scripts {
<script src="@Url.Content("~/ViewScripts/Competencia/Index.js")" type="text/javascript"></script>
}
@节脚本{
}
显然,在里面找不到PopularGridArquivo方法。
代码如下:
Competencia/Index.js
/// <reference path="Competencia.js" />
function PopularGridArquivo(mes) {
if (mes != "") {
$.ajax({
url: '/Competencia/ListarArquivosCompetencia',
type: 'post',
data: {
competencia: mes,
caminhoArquivo: $("#path").val()
},
success: function (html) {
$("#divDetalhe").html(html);
},
error: function (a, b, c) {
alert(c);
}
});
}
else {
$("#divdetalhe").html('');
}
}
//
功能PopularGridArquivo(mes){
如果(mes!=“”){
$.ajax({
url:“/Competencia/ListarArquivosCompetencia”,
键入:“post”,
数据:{
competencia:mes,
卡米霍尔基沃:$(“#路径”).val()
},
成功:函数(html){
$(“#divDetalhe”).html(html);
},
错误:函数(a、b、c){
警报(c);
}
});
}
否则{
$(“#divdetalhe”).html(“”);
}
}
主计长:
public class CompetenciaController : Controller
{
//
// GET: /Competencia/
public ActionResult Index()
{
Competencia compet = new Competencia();
compet.pathCompetencias = @"c:\temp\MUMPS\";
ViewBag.Competencia = compet;
return View(compet);
}
[HttpPost]
//public PartialViewResult ListarArquivosCompetencia(string competencia, string caminhoArquivo)
public PartialViewResult ListarArquivosCompetencia(string competencia, string caminhoArquivo)
{
IList<FileInfo> listaArquivos = null;
IList<CargaArquivos> listaCargaArquivos = new List<CargaArquivos>();
CargaArquivos oCargaArquivos = null;
//Popular combo de meses
//caminhoArquivo = System.Configuration.ConfigurationManager.AppSettings["FullPathExcelCalculoFechamentoMumps"].ToString();
//string caminhoArquivo = System.Configuration.ConfigurationManager.AppSettings["FullPathExcelCalculoFechamentoMumps"].ToString();
//DateTime data = new DateTime(DateTime.Now.Year, mes, 1);
caminhoArquivo = string.Format("{0}{1:MMyyyy}", caminhoArquivo, competencia);
listaArquivos = PastaArquivo.ListarArquivosDiretorio(caminhoArquivo);
if (listaArquivos.Count > 0)
{
foreach (var item in listaArquivos)
{
oCargaArquivos = new CargaArquivos();
oCargaArquivos.CaminhoArquivo = item.DirectoryName;
oCargaArquivos.NomeArquivo = item.Name;
listaCargaArquivos.Add(oCargaArquivos);
}
ViewBag.listaCargaArquivos = listaCargaArquivos;
}
//return PartialView("_DetalheCarga", ViewBag.listaCargaArquivos);
return PartialView("_DetalheCarga", ViewBag.listaCargaArquivos);
}
}
公共类控制器:控制器
{
//
//获得竞争优势/
公共行动结果索引()
{
Compencia compet=新Compencia();
compet.pathcompercenticas=@“c:\temp\MUMPS\”;
ViewBag.compencia=compet;
返回视图(compet);
}
[HttpPost]
//公共部分搜索结果列表符合要求(字符串竞争,字符串Caminoharquivo)
公共部分搜索结果列表符合要求(字符串竞争,字符串Caminoharquivo)
{
IList listaArquivos=null;
IList listaCargarquivos=新列表();
CargaArquivos-CargaArquivos=null;
//流行连音
//caminhoArquivo=System.Configuration.ConfigurationManager.AppSettings[“FullPathExcelCalculoFechamentoMumps”].ToString();
//字符串caminhoArquivo=System.Configuration.ConfigurationManager.AppSettings[“FullPathExcelCalculoFechamentoMumps”].ToString();
//日期时间数据=新的日期时间(DateTime.Now.Year,mes,1);
caminhoArquivo=string.Format(“{0}{1:MMyyyy}”,caminhoArquivo,competencia);
listaArquivos=PastaArquivo.ListarArquivosDiretorio(caminhoArquivo);
如果(listaArquivos.Count>0)
{
foreach(列表中的var项)
{
oCargaArquivos=新的CargaArquivos();
oCargaArquivos.CaminhoArquivo=item.DirectoryName;
oCargaArquivos.nomerquivo=项目名称;
添加(oCargaArquivos);
}
ViewBag.listaCargarquivos=listaCargarquivos;
}
//返回部分视图(“DetalheCarga”,ViewBag.listacargarquivos);
返回部分视图(“DetalheCarga”,ViewBag.listacargarquivos);
}
}
/视图/Competencia/Index.cshtml
@model IcatuValor.Models.Competencia
@section Scripts {
<script src="@Url.Content("~/ViewScripts/Competencia/Index.js")" type="text/javascript"></script>
}
<fieldset>
<div class="left-column">
@Html.Hidden("path", Model.pathCompetencias)
<label class="control-label"> Competência: @Html.DropDownList("ddMeses", new SelectList(Model.Competencias, "Key", "Value"), "Selecione", new { onChange = "JavaScript: PopularGridArquivo(this.value);", @class = "dropdown" })</label>
</div>
<div id="divDetalhe"></div>
@{
if (Model.arquivos != null)
{
Html.RenderPartial("_DetalheCarga", (IList<ViewModels.CargaArquivos>)ViewBag.listaCargaArquivos);
//Html.Partial("_DetalheCarga");
}
}
</fieldset>
@section Scripts {
<script src="@Url.Content("~/ViewScripts/CargaMumps/Index.js")" type="text/javascript"></script>
}
<fieldset>
<legend>Carregar Arquivos</legend>
@*<div class="input-append date datepicker" data-date-format="dd/mm/yyyy">
<label class="lbl">Data início</label>
<input type="text" class="datePicker" name="DataInicio" id="DataInicio" style="width: auto">
</div>*@
<div class="input-append" id="divArquivos">
<div class="input-append">
<label class="control-label">LF02 (LF02AAAAMM.TXT):</label>
@Html.TextBox("filLF02", null, new { type = "file", @class = "input-large" })
</div>
<div class="input-append">
<label class="control-label">LF03 (LF03AAAAMM.TXT):</label>
@Html.TextBox("filLF03", null, new { type = "file", @class = "input-large" })
</div>
<div class="input-append">
<label class="control-label">Pendência Atual (PendentesAAAAMM.txt):</label>
@Html.TextBox("filPendentes", null, new { type = "file", @class = "input-large" })
</div>
<div class="input-append">
<label class="control-label">Pendência Anterior (PendentesAAAAMM.txt):</label>
@Html.TextBox("filPendentesAnterior", null, new { type = "file", @class = "input-large" })
</div>
<br />
<div class="input-append">
<button type="submit" class="btn btn-primary" id="btnSubmit">Executar Matemática</button>
</div>
</div>
</fieldset>
<fieldset>
@{
//RENDERS OK
Html.RenderPartial("~/Views/Competencia/Index.cshtml", (IcatuValor.Models.Competencia)ViewBag.Competencia);
}
</fieldset>
@model-IcatuValor.Models.Competencia
@节脚本{
}
@Html.Hidden(“路径”,Model.PathCompetinces)
Competência:@Html.DropDownList(“ddMeses”,新选择列表(Model.Competencias,“Key”,“Value”),“Selecione”,新{onChange=“JavaScript:PopularGridArquivo(this.Value);”,@class=“dropdown”})
@{
如果(Model.arquivos!=null)
{
RenderPartial(“_DetalheCarga”,(IList)ViewBag.listaCargarquivos);
//Html.Partial(“_DetalheCarga”);
}
}
Competencia车型:
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
namespace IcatuValor.Models
{
public class Competencia
{
public string pathCompetencias { get; set; }
public string pathSubDir { get; set; }
public IEnumerable<KeyValuePair<string, string>> Competencias
{
get
{
//Expressão regular para validar o nome da pasta como formato MMYYYY
var re = new Regex(@"^(0[1-9]|1[0-2])(19|2[0-1])\d{2}$");
DirectoryInfo dirInfo = new DirectoryInfo(pathCompetencias);
foreach (DirectoryInfo dir in dirInfo.GetDirectories())
{
//Somente entram na listagem diretórios que satisfizerem o formato MMYYYY
if (re.IsMatch(dir.Name))
yield return new KeyValuePair<string, string>
(
dir.Name,
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Convert.ToInt16(dir.Name.Substring(0, 2))) + "/" + dir.Name.Substring(2)
);
}
}
}
public IList<DirectoryInfo> Subdiretorios
{
get
{
DirectoryInfo di = new DirectoryInfo(pathSubDir);
return di.GetDirectories();
}
}
public IList<FileInfo> arquivos
{
get;
set;
}
}
}
使用系统;
使用System.Collections.Generic;
利用制度全球化;
使用System.IO;
使用System.Linq;
使用System.Text.RegularExpressions;
使用System.Web;
命名空间为Uvalor.Models
{
公开课竞赛
{
公共字符串路径{get;set;}
公共字符串pathSubDir{get;set;}
公共数字竞争
{
得到
{
//定期速递格式面食
var re=new Regex(@“^(0[1-9]| 1[0-2])(19|2[0-1])\d{2}$”;
DirectoryInfo dirInfo=新的DirectoryInfo(路径竞争);
foreach(dirInfo.GetDirectories()中的DirectoryInfo目录)
{
//有些人在制定计划时会对格式感到满意
if(关于IsMatch(目录名称))
返回新的KeyValuePair
(
董事姓名,
CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Convert.ToInt16(目录名称子字符串(0,2))+“/”+目录名称子字符串(2)
);
}
}
}
公共IList子目录
{
得到
{
DirectoryInfo di=新的DirectoryInfo(路径子目录);
返回di.getDirectory();
}
}
公共图书馆
{
得到;
设置
}
}
}
最后是另一个页面,其中将使用“Competencia”:
Cargamumps/Index.cshtml
@model IcatuValor.Models.Competencia
@section Scripts {
<script src="@Url.Content("~/ViewScripts/Competencia/Index.js")" type="text/javascript"></script>
}
<fieldset>
<div class="left-column">
@Html.Hidden("path", Model.pathCompetencias)
<label class="control-label"> Competência: @Html.DropDownList("ddMeses", new SelectList(Model.Competencias, "Key", "Value"), "Selecione", new { onChange = "JavaScript: PopularGridArquivo(this.value);", @class = "dropdown" })</label>
</div>
<div id="divDetalhe"></div>
@{
if (Model.arquivos != null)
{
Html.RenderPartial("_DetalheCarga", (IList<ViewModels.CargaArquivos>)ViewBag.listaCargaArquivos);
//Html.Partial("_DetalheCarga");
}
}
</fieldset>
@section Scripts {
<script src="@Url.Content("~/ViewScripts/CargaMumps/Index.js")" type="text/javascript"></script>
}
<fieldset>
<legend>Carregar Arquivos</legend>
@*<div class="input-append date datepicker" data-date-format="dd/mm/yyyy">
<label class="lbl">Data início</label>
<input type="text" class="datePicker" name="DataInicio" id="DataInicio" style="width: auto">
</div>*@
<div class="input-append" id="divArquivos">
<div class="input-append">
<label class="control-label">LF02 (LF02AAAAMM.TXT):</label>
@Html.TextBox("filLF02", null, new { type = "file", @class = "input-large" })
</div>
<div class="input-append">
<label class="control-label">LF03 (LF03AAAAMM.TXT):</label>
@Html.TextBox("filLF03", null, new { type = "file", @class = "input-large" })
</div>
<div class="input-append">
<label class="control-label">Pendência Atual (PendentesAAAAMM.txt):</label>
@Html.TextBox("filPendentes", null, new { type = "file", @class = "input-large" })
</div>
<div class="input-append">
<label class="control-label">Pendência Anterior (PendentesAAAAMM.txt):</label>
@Html.TextBox("filPendentesAnterior", null, new { type = "file", @class = "input-large" })
</div>
<br />
<div class="input-append">
<button type="submit" class="btn btn-primary" id="btnSubmit">Executar Matemática</button>
</div>
</div>
</fieldset>
<fieldset>
@{
//RENDERS OK
Html.RenderPartial("~/Views/Competencia/Index.cshtml", (IcatuValor.Models.Competencia)ViewBag.Competencia);
}
</fieldset>
@节脚本{
}
卡雷加·阿奎沃斯
@*
信息中的数据
*@
LF02(LF02aamm.TXT):
@TextBox(“filLF02”,null,new{type=“file”,@class=“input large”})
LF03(lf03aamm.TXT):
@TextBox(“filLF03”,null,new{type=“file”,@class=“input large”})
Pendência Atual(pendentsaaaamm.txt):
@TextBox(“filPendentes”,null,新{type=“file”,@class=“input large”})
Pendentsaaaamm.txt:前牙区(Pendentsaaaaaamm.txt):
@TextBox(“Filpendentsanterior”,null,new{type=“file”,@class=“input large”})
E
Html.DisplayFor(m => m);